如何导航到JSF中的另一个页面?

时间:2015-01-11 08:50:03

标签: jsf primefaces

我正在使用JSF / PrimeFaces开发小型网络应用程序。我可以从web调用bean,但是,我无法返回web。这就是我所拥有的:

requestLeave.xhtml

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <h:head>
        <title>Request leave</title>
    </h:head>

    <h:body>
        <script language="javascript">
            var today = new Date();
            document.write(today);
        </script>

        <h:form id="form"  >
            <h:panelGrid id= "grid" columns="2" cellpadding="5">
                <f:facet name="header">
                    <p:messages id="msgs" />
                </f:facet>

                <h:outputLabel for="title" value="Leave Title:" style="font-weight:bold" />
                <p:inputText  value="#{requestLeave.titleLeave}" required="true" requiredMessage="title is required." />

                <h:outputLabel for="type" value="Type:" style="font-weight:bold" />
                <p:inputText  value="#{requestLeave.typeLeave}" required="true" requiredMessage="type is required." />

                <p:commandButton value="Submit" actionListener="#{requestLeave.buttonAction}"  />
            </h:panelGrid>
        </h:form>
    </h:body>
</html>

RequestLeave.java

import javax.faces.bean.ManagedBean;    

@ManagedBean    
public class RequestLeave {

    private String titleLeave;
    private String typeLeave;

    public String getTitleLeave() {
        return titleLeave;
    }

    public void setTitleLeave(String titleLeave) {
        this.titleLeave = titleLeave;
    }

    public String getTypeLeave() {
        return typeLeave;
    }

    public void setTypeLeave(String typeLeave) {
        this.typeLeave = typeLeave;
    }

    public String buttonAction() {

        System.out.println("leave title " + titleLeave);
        System.out.println("leave type " + typeLeave);

        return ("index.jsp");
    }
}

有了这个,我无法返回index.jsp。谁能帮我?提前谢谢。

1 个答案:

答案 0 :(得分:3)

actionListener属性更改为action

<p:commandButton value="Submit" action="#{requestLeave.buttonAction}" />

更多信息: