【问题标题】:How can I navigate to another page in JSF?如何导航到 JSF 中的另一个页面?
【发布时间】:2015-01-11 22:20:33
【问题描述】:

我正在使用 JSF/PrimeFaces 开发小型 Web 应用程序。我可以从 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。谁能帮我?提前致谢。

【问题讨论】:

    标签: jsf primefaces


    【解决方案1】:

    actionListener 属性更改为action

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

    更多信息:

    【讨论】:

    • 谢谢你,它解决了我的问题。但是,只有基本的 html 会呈现在新的导航页面中。有什么方法可以让我的 primefaces 组件出现在页面中?
    • 这是另一个问题,您应该为其创建一个新线程。对您的一些研究也可能是合理的,因为有很多线程可供您使用。
    猜你喜欢
    • 2015-08-12
    • 2021-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多