0

I am developing an application where I have to show data from the database based on User Input (let's say field empid for employee id and I show some information from database based on this input). I am using JSF, PrimeFace and Hibernate.

Now I have the index.xhtml page where I am taking input the empid. After that, I have to redirect to another page page2.xhtml.

Here is a snippet from index.xhtml:

     <h:form>
        <p>Employee ID:
            <p:inputText value="#{userBean.newuser.empid}" required="true"/></p>
     </h:form>
     <br />
     <h:form>
         <p:commandButton action="page2?faces-redirect=true" value="Enter" />      
     </h:form>  

But after re-directing to page2.xhtml, the empid input from index.xhtml page is lost. I tried to read a few posts on this but was not able to understand. Please help. I am sorry if it is a repeated question.

rkarwayun
  • 23
  • 1
  • 1
  • 7

1 Answers1

2

I assume that viewscopes of managed bean in which you are insterested in are @RequestScope ? You could specify more wide view scope for a managed bean, so it won't be destroyed after each request. However @RequestScope is really good when want to minimize session scope bloat. To stay with this session scope you could use flash object which was introduced with JSF 2.0. Thanks to this object you can transfer data between requests. You could put following code snippet :

ExternalContext.getFlash().put("empid", newuser.getEmpid);

in your userBean. After redirect you could retrieve that value on jsf page in the following way :

#{flash.empid}

Or in your managed bean :

ExternalContext.getFlash().get("empid");

More about flash with example can be found in this post or in JSF 2 Flash documentation

Community
  • 1
  • 1
Artur Skrzydło
  • 1,135
  • 18
  • 37