且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jsf登录超时

更新时间:2023-12-04 18:24:17

更新

从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.