注意
我有ServletFilter
,用于检查用户是否已通过使用<url-pattern>
登录。如果用户未登录,则重定向至login.xhtml
。
我的问题
用户登录后,我的程序总是重定向dashboard.xml
(基于navigation-rule
)。我想自动重定向last visited page
。你能提供可能的方法吗?
目前我的解决方案正在为此工作
但是,我不乐意使用它。Seam
支持吗?你能提供更好的方法吗?
在我的ServletFilter
中,我保留上次访问的页面如下
身份验证筛选器.java
httpSession.setAttribute(Constants.ORIGINAL_VIEW_KEY, requestPath);
在我的LoginBean
中,在用户登录后重定向上次访问的页面。
登录豆.java
ELContext elContext = facesContext.getELContext();
Application application = facesContext.getApplication();
ExpressionFactory eFactory = application.getExpressionFactory();
ValueExpression binding = eFactory.createValueExpression(elContext, "#{" + Constants.VISIT_KEY_SCOPE + Constants.VISIT_KEY + "}", Visit.class);
binding.setValue(elContext, visit);
ValueExpression originalViewBinding = eFactory.createValueExpression(elContext, "#{" + Constants.ORIGINAL_VIEW_SCOPE + Constants.ORIGINAL_VIEW_KEY + "}", String.class);
String originalViewId = (String) originalViewBinding.getValue(elContext); <--- last visited view id.
UIViewRoot viewRoot = application.getViewHandler().createView(facesContext, originalViewId) ;
facesContext.setViewRoot(viewRoot);
facesContext.renderResponse();
从login.page中删除以下内容.xml
<navigation from-action="#{identity.login}">
<rule if="#{identity.loggedIn}">
<redirect view-id="/view/dashboard.xhtml"/>
</rule>
>如果使用Identity
和Credentials
,则页面在登录后自动重定向上次访问的页面(要访问该页面,使用需要登录)。我们必须需要按如下方式进行配置component.xml
。
组件.xml
<?xml version="1.0" encoding="UTF-8"?>
<components ----->
<event type="org.jboss.seam.security.loginSuccessful">
<action execute="#{redirect.returnToCapturedView}"/>
</event>
</components>