您可以使用过期的会话发布到JSF2页面吗? [英] Can you POST to JSF2 page with an expired session?

查看:84
本文介绍了您可以使用过期的会话发布到JSF2页面吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用JSF1.2来登录页面.如果用户在登录页面上坐了太长时间(超时情况),然后尝试输入ID和密码,则它将失败并显示ViewExpired错误(即使ID/密码正确).从JSF的角度来看,这一切对我来说都是有意义的.我的解决方案是仅对javax.faces.STATE_SAVING_METHOD使用Client.但这感觉就像是骇客.

I have been using JSF1.2 for login pages. If the user sits on the login page for too long (timeout situatation) and then tries to enter the id and password it fails with ViewExpired error (even though the id/password are correct). This all makes sense from JSF perspective to me. My solution has been to simply use Client for javax.faces.STATE_SAVING_METHOD. But that feels like a hack.

我的应用程序正在迁移到JSF2.0.我希望我的应用回到服务器上以STATE_SAVING_METHOD.但是我的要求是,如果提交了正确的ID和密码,该应用程序将接受它.

My app is migrating to JSF2.0. I would like my app to go back to server for STATE_SAVING_METHOD. But my requirement is that if the proper ID and password are submitted that app will accept it.

我的另一个解决方案是仅使用servlet,而不使用JSF进行登录处理.但是似乎所有JSF2.0的丑陋之处现在都可以提供.

My other solution is to simply use servlets and not use JSF for login processing. But it seems like with all the ugprades to JSF2.0 that there might be something available now.

任何想法都将不胜感激. 谢谢.

Any ideas would be greatly appreciated. Thank you.

推荐答案

您可以手动还原的视图 ViewHandler .这是一个启动示例:

You could manually create and build the view when the restored view returns null during postback. You can do this in a custom ViewHandler. Here's a kickoff example:

public class RestorableViewHandler extends ViewHandlerWrapper {

    private ViewHandler wrapped;

    public RestorableViewHandler(ViewHandler wrapped) {
        this.wrapped = wrapped;
    }

    @Override
    public UIViewRoot restoreView(FacesContext context, String viewId) {
        UIViewRoot restoredView = wrapped.restoreView(context, viewId);

        if (!(restoredView == null && context.isPostback())) {
            return restoredView;
        }

        UIViewRoot createdView = createView(context, viewId);
        context.setViewRoot(createdView);

        try {
            getViewDeclarationLanguage(context, viewId).buildView(context, createdView);
        } catch (IOException e) {
            throw new FacesException(e);
        }

        return createdView;
    }

    @Override
    public ViewHandler getWrapped() {
        return wrapped;
    }

}

您可能想通过检查viewId是否代表登录页面来扩展if检查.

You may want to extend the if check with a check if the viewId represents the login page.

要使其运行,请在faces-config.xml中进行如下注册:

To get it to run, register it as follows in faces-config.xml:

<application>
    <view-handler>com.example.RestorableViewHandler</view-handler>
</application>

但是,存在技术限制:重新创建的视图与初始请求期间的视图完全相同,因此对JSF组件树的任何修改都是由标记处理程序或基于某个视图甚至是条件渲染的组件进行的,甚至会话作用域变量,将完全丢失.为了精确地重新创建所需的视图,您需要确保这些修改是基于请求范围的变量(读取:请求参数)而不是视图或会话范围的变量进行的.

There are however technical limitations: the recreated view is exactly the same as it was during the initial request, so any modifications to the JSF component tree which are made thereafter, either by taghandlers or conditionally rendered components based on some view or even session scoped variables, are completely lost. In order to recreate exactly the desired view, you would need to make sure that those modifications are made based on request scoped variables (read: request parameters) instead of view or session scoped variables.

换句话说,视图的状态不应依赖于视图或会话范围的托管Bean,而应完全依赖于请求范围的托管Bean.

In other words, the state of the view should not depend on view or session scoped managed beans, but purely on request scoped managed beans.

更新: OmniFaces JSF实用程序库在当前的1.3快照中具有可重用的解决方案,该解决方案<o:enableRestorableView>的风格,可以嵌入<f:metadata>中.另请参见 <o:enableRestorableView>快照站点上的展示页面以获得演示.

Update: the OmniFaces JSF utility library has in the current 1.3 snapshot a reuseable solution in flavor of <o:enableRestorableView> which can be embedded in <f:metadata>. See also the <o:enableRestorableView> showcase page on snapshot site for a demo.

这篇关于您可以使用过期的会话发布到JSF2页面吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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