【问题标题】:Unable to find matching navigation case with from-view-id无法使用 from-view-id 找到匹配的导航案例
【发布时间】:2017-09-07 16:49:19
【问题描述】:

我正在尝试实现简单的页面导航。所以每当我点击登录按钮时,它应该只是将我重定向到欢迎页面并显示欢迎消息。

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head>
        <title>External Resources</title>        
    </h:head>
    <h:body>
        <ui:composition template="/WEB-INF/templates/template.xhtml">
            <ui:define name="css">
                <h:outputStylesheet library="css" name="index.css"/>
            </ui:define>
            <ui:define name="content">
                <h1>Welcome to Login Page</h1>
                    <h:form id="login-form" prependId="false">
                        <h:panelGrid columns="5">
                            <h:outputLabel for="username" value="Username"/>
                  <h:inputText id="username" value="#{loginBean.user.username}" />

                            <h:outputLabel for="password" value="Password"/>
                <h:inputSecret id="password" value="#{loginBean.user.password}" />

                            <h:commandButton value="Login" id="cmdButton" 
                            action="#{loginBean.goToWelcome()}"/>
                        </h:panelGrid>
                    </h:form>
            </ui:define>
        </ui:composition>
    </h:body>
</html>

这是我的登录 bean,它包含一个返回字符串的 goToWelcome 方法。

LoginBean.java

@SessionScoped
@ManagedBean
public class LoginBean implements Serializable{

    private User user;
    public LoginBean(){

    }

    @PostConstruct
    public void init(){
        user= new User();
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public String goToWelcome(){
        return "/pages/welcome?faces-redirect=true";
    }

}

错误说:-

Unable to find matching navigation case with from-view-id 
'/index.xhtml' for action '#{loginBean.goToWelcome()}' with outcome 
'/pages/welcome?faces-redirect=true'

【问题讨论】:

    标签: jsf jsf-2.2


    【解决方案1】:

    返回页面的方式有很多种!


    非常简单的一个:例如在您的 backingBean 中返回这样的页面:

    return "DesiredPage.xhtml";

    该页面必须位于 WebPages 文件夹中。

    【讨论】:

      猜你喜欢
      • 2016-07-21
      • 1970-01-01
      • 2017-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-14
      • 1970-01-01
      相关资源
      最近更新 更多