0

当用户转到登录页面并且已经登录时,我正在尝试完成到主页的重定向。这就是我定义规则的方式:

<navigation-rule>
    <from-view-id>/login.xhtml</from-view-id>
    <navigation-case>
        <if>#{identity.loggedIn}</if>
        <to-view-id>/home.xhtml</to-view-id>
        <redirect />
    </navigation-case>
 </navigation-rule>

但我得到了下一个例外:

WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] (default task-26) Error de argumento: el parámetro id es nulo: java.lang.NullPointerException: Error de argumento: el parámetro id es nulo
at com.sun.faces.util.Util.notNull(Util.java:425) [jsf-impl-2.2.0-jbossorg-2.jar:]
at com.sun.faces.flow.FlowHandlerImpl.getFlow(FlowHandlerImpl.java:89) [jsf-impl-2.2.0-jbossorg-2.jar:]
at com.sun.faces.application.NavigationHandlerImpl.determineViewFromActionOutcome(NavigationHandlerImpl.java:1204) [jsf-impl-2.2.0-jbossorg-2.jar:]
at com.sun.faces.application.NavigationHandlerImpl.findExactMatch(NavigationHandlerImpl.java:568) [jsf-impl-2.2.0-jbossorg-2.jar:]
at com.sun.faces.application.NavigationHandlerImpl.getViewId(NavigationHandlerImpl.java:462) [jsf-impl-2.2.0-jbossorg-2.jar:]
at com.sun.faces.application.NavigationHandlerImpl.handleNavigation(NavigationHandlerImpl.java:189) [jsf-impl-2.2.0-jbossorg-2.jar:]
at com.sun.faces.application.NavigationHandlerImpl.handleNavigation(NavigationHandlerImpl.java:182) [jsf-impl-2.2.0-jbossorg-2.jar:]
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:132) [jsf-impl-2.2.0-jbossorg-2.jar:]
at javax.faces.component.UICommand.broadcast(UICommand.java:315) [jboss-jsf-api_2.2_spec-2.2.0.jar:2.2.0]
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790) [jboss-jsf-api_2.2_spec-2.2.0.jar:2.2.0]
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282) [jboss-jsf-api_2.2_spec-2.2.0.jar:2.2.0]
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) [jsf-impl-2.2.0-jbossorg-2.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.2.0-jbossorg-2.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) [jsf-impl-2.2.0-jbossorg-2.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) [jboss-jsf-api_2.2_spec-2.2.0.jar:2.2.0]
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:87) [undertow-servlet-1.0.0.Beta3.jar:1.0.0.Beta3]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130) [undertow-servlet-1.0.0.Beta3.jar:1.0.0.Beta3]
at io.undertow.websockets.jsr.JsrWebSocketFilter.doFilter(JsrWebSocketFilter.java:138) [undertow-websockets-jsr-1.0.0.Beta3.jar:1.0.0.Beta3]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:56) [undertow-servlet-1.0.0.Beta3.jar:1.0.0.Beta3]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.0.0.Beta3.jar:1.0.0.Beta3]
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85) [undertow-servlet-1.0.0.Beta3.jar:1.0.0.Beta3]
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:82) [undertow-servlet-1.0.0.Beta3.jar:1.0.0.Beta3]
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.0.Beta3.jar:1.0.0.Beta3]
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:115) [undertow-servlet-1.0.0.Beta3.jar:1.0.0.Beta3]
at io.undertow.security.handlers.AuthenticationCallHandler.handleRequest(AuthenticationCallHandler.java:52) [undertow-core-1.0.0.Beta3.jar:1.0.0.Beta3]
at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51) [undertow-core-1.0.0.Beta3.jar:1.0.0.Beta3]
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.0.Beta3.jar:1.0.0.Beta3]
at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:55) [undertow-servlet-1.0.0.Beta3.jar:1.0.0.Beta3]
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:65) [undertow-servlet-1.0.0.Beta3.jar:1.0.0.Beta3]
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:70) [undertow-core-1.0.0.Beta3.jar:1.0.0.Beta3]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Beta3.jar:1.0.0.Beta3]
at org.wildfly.extension.undertow.security.SecurityContextCreationHandler.handleRequest(SecurityContextCreationHandler.java:54)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Beta3.jar:1.0.0.Beta3]
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:185) [undertow-servlet-1.0.0.Beta3.jar:1.0.0.Beta3]
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:172) [undertow-servlet-1.0.0.Beta3.jar:1.0.0.Beta3]
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:56) [undertow-servlet-1.0.0.Beta3.jar:1.0.0.Beta3]
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:107) [undertow-servlet-1.0.0.Beta3.jar:1.0.0.Beta3]
at io.undertow.server.HttpHandlers.executeRootHandler(HttpHandlers.java:36) [undertow-core-1.0.0.Beta3.jar:1.0.0.Beta3]
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:629) [undertow-core-1.0.0.Beta3.jar:1.0.0.Beta3]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_25]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_25]

重定向被释放,但引发异常。怎么能解决?

4

2 回答 2

0
<navigation-rule>
<from-view-id>/login.xhtml</from-view-id>
<navigation-case>
    <from-outcome>logged</from-outcome>
    <to-view-id>home.xhtml</to-view-id>
    <redirect />
</navigation-case>

** “logged”是从loggedIn方法返回的值

于 2014-08-31T18:14:19.213 回答
0

检查源代码后,问题与结果有关:

com.sun.faces.flow.FlowHandlerImpl.getFlow 方法需要 Id 不为空:

public Flow getFlow(FacesContext context, String definingDocumentId, String id) {
    Util.notNull("context", context);
    Util.notNull("definingDocumentId", definingDocumentId);
    Util.notNull("id", id);

com.sun.faces.application.NavigationHandlerImpl:

result.isFlowEntryFromExplicitRule = null != fh.getFlow(ctx, toFlowDocumentId, outcome);

所以结果是空的,异常就出现了。就我而言,我没有结果。

如果从结果中需要,那么必须在某个地方执行一个动作。为了实现这个 login.xhtml 页面需要一个f:viewAction

现在实现所有这一切,我请求的用例运行良好。如果 声明了from-action,则from-outcome是可选的,反之亦然。

如果用户转到根文件夹(域/应用程序名/)时需要相同的重定向逻辑,那么唯一要做的就是将欢迎文件添加到 web.xml。

<welcome-file>login.jsf</welcome-file>

最后这是导航规则声明

<navigation-rule>
    <from-view-id>/login.xhtml</from-view-id>
    <navigation-case>
        <!--optional<from-action>#{bean.loggedInNavigationRuleAction}</from-action>-->
        <from-outcome>logged</from-outcome>
        <if>#{identity.loggedIn}</if>
        <to-view-id>/home.xhtml</to-view-id>
        <redirect />
    </navigation-case>
 </navigation-rule>

这必须添加到 login.xhtml

<f:metadata>
  <f:viewParam name="x" value="#{bean.x}"/>
  <f:viewAction action="#{bean.loggedInNavigationRuleAction}" phase="APPLY_REQUEST_VALUES"/>
</f:metadata>
于 2013-10-31T18:20:50.907 回答