Primefaces ajax not firing request event from commandlink after page navigation JPA persistence

风流意气都作罢 提交于 2019-12-13 05:24:59

问题


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.

来源:https://stackoverflow.com/questions/34925720/primefaces-ajax-not-firing-request-event-from-commandlink-after-page-navigation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!