Jsf login time

Ok, a simple question. I have a JSF application containing a login page. The problem is that the user loads the login page, leaves it for a while, then tries to enter the session, and the ViewExpiredException is thrown. I can redirect back to login when this happens, but it is not very smooth. How can I let this thread enter correctly without an extra attempt?

+4
source share
4 answers

Update

As in Mojarra 2.1.19 / 2.2.0, now you can set the transition attribute <f:view> to true:

 <f:view transient="true"> Your regular content </f:view> 

Here you can read the Balusc blog:

http://balusc.blogspot.com.br/2013/02/stateless-jsf.html

Original

If you use Facelets, you can create your own ViewHandler to handle this:

 public class LoginViewHandler extends FaceletViewHandler { public LoginViewHandler( ViewHandler viewHandler ) { super( viewHandler ); } @Override public UIViewRoot restoreView( FacesContext ctx, String viewId ) { UIViewRoot viewRoot = super.restoreView( ctx, viewId ); if ( viewRoot == null && viewId.equals( "/login.xhtml" ) ) { // Work around Facelet issue initialize( ctx ); viewRoot = super.createView( ctx, viewId ); ctx.setViewRoot( viewRoot ); try { buildView( ctx, viewRoot ); } catch ( IOException e ) { log.log( Level.SEVERE, "Error building view", e ); } } return viewRoot; } } 

Change "/login.xhtml" to your login page. This checks to see if it can restore your view, and if it cannot, and the current view is your login page, it will create and create a view for you.

Install this in your face-config.xml as follows:

 <application> <!-- snip --> <view-handler>my.package.LoginViewHandler</view-handler> </application> 

If you use JSF without Facelets (i.e. JSP), you can try to make the class extend ViewHandlerWrapper - note that buildView () will not be available. I hope that createView () on it will set the view itself correctly, but I'm not 100% sure with JSF / JSP.

+6
source

Some slightly hacked solutions:

  • (Very hacks) use the <meta http-equiv="refresh" content="5"/> to automatically reload the page as often.
  • Use the JavaScript function to periodically send the ping request to the server to save the session.

We use IceFaces at work, which automatically detects when your session has expired and displays a pop-up warning about this fact. But for some reason, we are still having problems on the login page.

0
source

It looks like your login page is in the session area when it’s really not necessary. The request area should be fine for the login page (since, as a rule, there should be nothing in the session before the user logs in). Once the user logs in, you may have a problem returning this problem, but Phill's ideas are very good there.

0
source

With jsp, you can disconnect a session for a page, including this directive <%@ page session="false" %> . There should be something like this for jsf.

0
source

All Articles