sandesh
sandesh

Reputation: 59

How can I navigate to another page in JSF?

I am developing small web app using JSF/PrimeFaces. I am able to call bean from web, however, I am unable to return web. This is what I have:

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");
    }
}

With this, I cannot return to index.jsp. Can anyone help me? Thanks in advance.

Upvotes: 1

Views: 6296

Answers (1)

Konstantin Yovkov
Konstantin Yovkov

Reputation: 62864

Change the actionListener attribute to action:

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

More info:

Upvotes: 3

Related Questions