0

This question is an MCVE related to Primefaces ajax not updating panel or panelGrid component in the same form

The application navigates between two JSF pages. The first is a user registration form which persists a new user (Reg.xhtml) and navigates to a user profile page (UserProfile.xhtml) where the user fills in a new profile.

The problem happens in the UserProfile.xhtml where an ajax action meant to fire a panel that shows the values entered by the user before the profile is persisted. The ajax request does not seem to be fired and the form to validate the user input is blank after clicking to fire the ajax event. The MCVE JSF and bean code to simulate the navigation from the registration to profile page:

Reg.xhtml:

    <h:form id="newuser">

                        <p:commandLink id="makefinal" value="Navigate"     
                                   action="#{userBean.makeUser}"
                                   ajax="false"/>
            </h:form>


@Named(value = "userBean")
@SessionScoped
public class UserBean implements Serializable {


public String makeUser() {

    return "/Main/Users/UserProfile";
}

}

JSF and bean code for the navigated profile page (Where the actual problem of the java action failing to execute):

The profile entity and form:

@Entity
public class Enprofile implements Serializable {
@Id
private String firstname;
@Temporal(TemporalType.DATE)
private Date dateofbirth;

public Enprofile() {
}

   public Enprofile(String firstname, Date dateofbirth) {
   this.firstname = firstname;
   this.dateofbirth = dateofbirth;
   }
  }

 <h:form id="proform">

                <p:panelGrid id="userpro" columns="2">


                    <p:outputLabel value="First Name:"/>
                    <p:inputText value="#{profileBean.proFirstName}"/>


                    <p:outputLabel value="Date of Birth:"/>
                    <p:calendar value="#{profileBean.dateofbirth}"/>

                     <p:commandLink id="make" value="Create"
                                    action="#{profileBean.checkProfile}"
                              process="userpro make"
                              update="usercheck"/>

                </p:panelGrid>

                <p:panelGrid id="usercheck" columns="2">


                    <p:outputLabel value="#{profileBean.newPro.firstname}"/>
                    <p:outputLabel value="#{profileBean.newPro.dateofbirth}"/>

                </p:panelGrid>

            </h:form>

Profile bean code:

@Named(value = "profileBean")
@RequestScoped
public class ProfileBean {

private Enprofile newPro;

public void checkProfile() {
    newPro = new Enprofile(firstName, dateofbirth);

    firstName = getFirstname();
    newPro.setFirstname(firstname);

    dateofbirth = getDateofbirth();
    newPro.setDateofbirth(dateofbirth);

}
}

I am not able to reproduce the problem using the above code and if the page is run WITHOUT a persist operation (using standard page navigation) it works perfectly. If there is a preceding persist operation (ie: creating a new user then navigating to the profile page), the view state seems to be somehow lost and the ajax function on the second page (profile page) are dead.

Community
  • 1
  • 1
jay tai
  • 419
  • 1
  • 17
  • 35
  • 2
    This is not a good MCVE. You're here basically implying that the problem disappears when you remove `border: 20px;` style, or when you remove `proSurname` field, or when you remove `` tags, or when you replace `proFacade` by hardcoded model (and so are many other things). In other words, there's irrelevant noise in the code distracting readers from the real problem. – BalusC Jan 21 '16 at 13:56
  • Even after this edit, the comment above remains valid. Read http://www.stackoverflow.com/tags/jsf/info – Kukeltje Jan 21 '16 at 14:04
  • I have tried to summarize the probem according to the above link provided. The first part simulates the navigation to the profile page (omitting the persistence actions for creating new user). The second part is where the problem happens, but I include the initial page navigation since I suspect the View State after navigation might be part of the problem. please let me know if this is ok. Thanks – jay tai Jan 21 '16 at 22:08

0 Answers0