jsf登录超时 [英] jsf login times out

查看:148
本文介绍了jsf登录超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好简单的问题.我有一个包含登录页面的JSF应用程序.问题是,如果用户加载了登录页面,将其保留了一段时间,然后尝试登录会话,则该会话到期并引发了ViewExpiredException.发生这种情况时,我可以重定向回登录名,但这并不是很顺利.我该如何允许此流正确登录而无需进行其他尝试?

Ok simple question. I have a JSF application, containing a login page. The problem is if the user loads the login page, leaves it for a while, then tries to login the session expires and a ViewExpiredException is thrown. I could redirect back to the login when this happens, but that isn't very smooth. How can I allow this flow to properly login without an additional attempt?

推荐答案

更新

从Mojarra 2.1.19/2.2.0开始,您现在可以将<f:view>的瞬态属性设置为true:

As of Mojarra 2.1.19 / 2.2.0 you can now set the transient attribute of the <f:view> to true:

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

您可以在 Balusc的博客中了解以下内容:

You can read about in on Balusc's blog here:

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

原始

如果您使用Facelets,则可以创建自己的ViewHandler来处理此问题:

If you're using 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;
    }
}

将"/login.xhtml"更改为登录页面.这将检查它是否可以还原您的视图,如果不能还原,并且当前视图是您的登录页面,它将为您创建和构建视图.

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 build the view for you.

在face-config.xml中进行如下设置:

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

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

如果您使用的是不带Facelets的JSF(即JSP),则可以尝试让类扩展ViewHandlerWrapper-请注意,buildView()将不可用.希望单独使用createView()可以正确设置视图,但是我不确定100%使用JSF/JSP.

If you're using JSF without Facelets (i.e. JSPs) you can try having the class extend ViewHandlerWrapper - note that buildView() will not be available. Hopefully createView() on it's own will set the view up correctly but I'm not 100% sure with JSF/JSP.

这篇关于jsf登录超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆