I am trying to write an application that registers a new user and lets them fill in a user profile after they have created their login details. I need another form to display an exact copy of what the user has entered as a validation, after which the user can accept or edit the entry before persisting the profile form.
The user is successfully created using the following action:
public String makeUser() {
if (nameAvailable = true) {
facade.create(newUser);
} else {
userMessage = "VALIDAION FAILED. Please try again and check that your uder name is not already taken";
}
selUser = newUser;
return "/Main/Users/UserProfile";
}
The user is then directed to a profile form:
<h:form id="proform">
<p:outputPanel id="propan">
<p:panelGrid id="userpro" columns="2">
<p:outputLabel value="Salutation"/>
<p:inputText value="#{userBean.salutation}"/>
<p:outputLabel value="First Name:"/>
<p:inputText value="#{userBean.proFirstName}"/>
<p:outputLabel value="Surame:"/>
<p:inputText value="#{userBean.proSurname}"/>
<p:outputLabel value="Date of Birth:"/>
<p:calendar value="#{userBean.dateofbirth}"/>
</p:panelGrid>
<p:commandLink id="make" value="Create"
action="#{userBean.checkProfile}"
process=":proform:make :proform:userpro"
update="proform:usercheck"/>
// also tried
process="userpro"
update="usercheck"/>
The following checkProfile action is used to create the validation form for the user to check their input (but does not seem to be getting executed) :
public void checkProfile() {
newPro = new Enprofile(salutation, proFirstName, proSurname, dateofbirth, selUser);
salutation = getSalutation();
newPro.setSaltuation(salutation);
proFirstName = getProFirstName();
newPro.setFirstname(proFirstName);
proSurname = getProSurname();
newPro.setSurname(proSurname);
dateofbirth = getDateofbirth();
newPro.setDateofbirth(dateofbirth);
selUser = getSelUser();
newPro.setUser(selUser);
System.out.println("New Profile First Name" + newPro.getFirstname());
setNewPro(newPro);
}
The user check form is:
<p:panelGrid id="usercheck" columns="2">
<p:outputLabel value="#{userBean.newPro.saltuation}"/>
<p:outputLabel value="#{userBean.newPro.firstname}"/>
<p:outputLabel value="#{userBean.newPro.surname}"/>
<p:outputLabel value="#{userBean.newPro.dateofbirth}"/>
<p:commandLink id="accept" value="Accept"
action="#{userBean.makeProfile}"
ajax="false"/>
</p:panelGrid>
</h:form>
When calling the checkProfile action from the profile form (id: proform), the usercheck form remains blank and the console shows no error messages.
Reading the PF documentation and the questions here, I know that the Ajax API consists of three fundamental functions
PrimeFaces.ajax.Request.handle(cfg);
PrimeFaces.ajax.Response
Since the console is totally blank it would suggest that the ajax request is not getting fired in the first place, which leads me to think that I'm doing something wrong in the process part of the checkProfile action?
UPDATE:
In response to BalusC's comment, please note I have gone through all of the points in the following question (marked as duplicate):
commandButton/commandLink/ajax action/listener method not invoked or input value not updated
Specifically I have adjusted looked at point 8
If you're using Ajax, then make sure that the UIInput and UICommand components of interest are covered by the
<f:ajax execute>
or e.g.<p:commandXxx process>
, otherwise they won't be executed/processed. See also Understanding process and update attributes of PrimeFaces.
<p:commandLink id="make" value="Create"
action="#{userBean.checkProfile}"
process=":proform:make :proform:userpro"
update=":proform:usercheck"/>
As above I think I have included the UIInput and UICommand in the process execution, but still no luck. The console does not even print the confirmation value for the newly created instance in the checkProfile method:
System.out.println("New Profile First Name" + newPro.getFirstname());
As for the other points in the question:
- 1) UICommand and UIINput components are inside an h:form tag
- 2) Multiple UIForm components do not seem to be nested
3) No input validation error seems to have occured and the following message tag shows blank:
<p:messages id="msg" for="make" showDetail="true" autoUpdate="true"/>
4) Components are not inside any iterating tag
5) No rendered attribute has been explicitly specified for any Component ** (i assume not explicitly specifying rendered attribute defaults to true??)**
- 6) No JS errors are recorded for the UIInput actions (or for anything else on the page)
- 7) There is an h:head in the master template
- 8) Both UICommand and UIInput components of interest are being included in the ajax process of the commandLink
- 9) There is only one form on the page (after the most recent edit)
- 10) The form does not contain enctype="multipart/form-data
11) I'm using a regular action tag in the commandLink
12) No calls to FacesContext#renderResponse() or
FacesContext#responseComplete() seems to have taken place by any
event listeners- 13) No Filter or Servlet in the same request-response chain has blocked the request fo the FacesServlet
On the final point (13), it may be possible that a request-response chain has disrupted (not blocked) the FacesServlet request. If I set the ajax value to false in the checkProfile action, it produces the following stack:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:604)
at java.util.ArrayList.get(ArrayList.java:382)
at javax.faces.component.AttachedObjectListHolder.restoreState(AttachedObjectListHolder.java:165)
at javax.faces.component.UIComponentBase.restoreState(UIComponentBase.java:1607)
at com.sun.faces.application.view.FaceletPartialStateManagementStrategy$2.visit(FaceletPartialStateManagementStrategy.java:380)
at com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:151)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1689)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at com.sun.faces.application.view.FaceletPartialStateManagementStrategy.restoreView(FaceletPartialStateManagementStrategy.java:367)
This suggests that there is there is a problem with restoring the view state, as there was previously a page rendered when a user was created. Do I need to refresh the View state?
I'm proposing that this question is not duplicate and there maybe more to the error than the 13 points mentioned in the dupe? Thanks