Doubts with JSF

-2

Well, I'm recently 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 clear my doubts, I'll be grateful.

NOTE: I'm using JSF with MVC standard

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

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

2)

which redirects to another page, and is widely 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 will be redirected to index.html. .. Since JSF does not work with JAVA code in the source code like PHP, it should have some command to manipulate in the MODEL, then I wanted to know if anyone knows this command.

    
asked by anonymous 08.12.2018 / 07:31

1 answer

0

For you to understand about the sessions, I suggest that you be a student in the JSF lifecycle . But briefly, it follows an image to illustrate the situation.

Here'saveryinterestingarticle: link

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

Request Scope : All objects stored in the request scope survive only a submission to the JSF life cycle (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 span among the scopes, so the objects remain for a short time in memory and it is freed more frequently and with this we have an application that tends to scale better.

Session Scope: All objects and attributes bound to ManagedBean will survive throughout the user session. The session is defined by the user's browser link 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 on cases where it was necessary to maintain the state of objects, currently this need can often be solved through View Scope.

Application Scope: Everything stored in this scope remains while the application is running and is shared among all users. It is recommended whenever it is necessary to store 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 for working with manual value caches, as an example list of states.

View Scope: added from JSF version 2, 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 maintain the data for as many requests as necessary, as long as all of these are performed for the same view. If a request is run for a different page and / or ManagedBean, the scope is cleaned, thus preventing unused objects from being kept alive for a long time (if that occurred in the session scope).

10.12.2018 / 12:56