Questions with JSF

Asked

Viewed 73 times

-2

Well, I am not long in Java WEB and I have some doubts in Javaserv Faces, and I would like to understand, to be able to manipulate well, etc. So if anyone can ask my questions, I would be grateful.

NOTE: I am using JSF with MVC standard

1) There are 2 types of sessions, the session that the DAO uses to access the database and the browser, the Browser Session stores all classes that are in the system?

Example: Imagine that I created a System that has 2 classes, being Client and Account... there have the Getters and Setters and also created the Controller Client and Controller account, since the View communicates with the Controller, and the Controller with the Model (Back-end). Ai, I joined the site and will automatically have these 2 objects as a Session variable? However, null? Then when I log in for example, the Session Client will receive the information from my account that I logged directly from the controller?

2) Page protection, I know a little bit about PHP, I understood and managed to manipulate well, and there is the header (Location index.html) command; which redirects to another page, and is quite used with the isset(var) command, for example, the guy is not logged in, so can not access such page, so if you try to access this protected page you will be redirected to index.html... Since JSF does not work with JAVA code in source code like PHP, it must have some command to manipulate in TEMPLATE, ai wondered if anyone knows this command.

1 answer

0

For you to understand about the sessions, I suggest you a studied at life cycle of JSF. But in summary, follow an image to illustrate the situation.

Clico de Vida JSF

Here’s an interesting article: https://www.devmedia.com.br/ciclo-de-vida-do-javaserver-faces-jsf/27893

In a very short way, you may have to control the objects of your "Goods":

Request Scope: all objects stored in the request scope survive only one JSF lifecycle submission (which I will explain in another post). With this we have a duration that matches the request being sent to the server, and this returning the response to the user who triggered the action. It has the shortest life time among the scopes, in this way, the objects remain for a short time in memory being released more frequently and with this we have an application that tends to climb better.

Session Scope: all objects and attributes linked to Managedbean will survive throughout the user’s session. The session is defined by the link of the user’s browser to the server. This way, if user opens two browsers, he will be creating two sessions with the server. This scope was widely used in JSF 1.x versions, to work in cases where it was necessary to maintain the state of objects, nowadays this need can often be solved through View Scope.

Application Scope: Everything stored in this scope remains as long as the application is running and is shared among all users. It is recommended whenever it is necessary to save information that can be used by various parts of the application as parameters and also implement functionalities to provide communication between users. This scope is also interesting to work with manual value caches, such as state list.

View Scope: added from version JSF 2, it was created to solve the problem of always using Session when it was necessary to keep the data between requests and that did not burden the application so much. View Scope supports the statefull model of the framework, where it is possible to keep data during as many requests as necessary, provided that all requests are made to the same view. If a request is executed for a different page and/or Managedbean, the scope is cleaned, thus preventing unused objects from remaining alive for a long time (in case it occurred in the session scope).


Browser other questions tagged

You are not signed in. Login or sign up in order to post.