无法找到与from-view-id

时间:2017-09-07 16:49:19

标签: jsf jsf-2.2

我正在尝试实现简单的页面导航。因此,每当我点击登录按钮时,它只需将我重定向到欢迎页面并显示欢迎信息。

<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'

1 个答案:

答案 0 :(得分:0)

有很多方法可以返回页面!

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

return "DesiredPage.xhtml";

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