1

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

Community
  • 1
  • 1
jay tai
  • 419
  • 1
  • 17
  • 35
  • 1
    See point 8 of dupe. – BalusC Jan 20 '16 at 09:01
  • I have looked at point 8 and updated the question. I think I'm now including both UICommand and UIInput in my process action now but the request STILL doesn't seem to be getting fired, so not sure if this question is really a dupe? Thank you! – jay tai Jan 20 '16 at 17:32
  • Then one of other points may apply. – BalusC Jan 20 '16 at 17:52
  • Yes they may, but I've gone through them and don't yet see where they do (pls see update). Would appreciate any clarification in case I missed anything but it's looking like a View state problem which doesn't seem to be covered in the dupe – jay tai Jan 20 '16 at 20:33
  • 1
    Are you `binding` a component beyond request scope? http://stackoverflow.com/questions/14911158/how-does-the-binding-attribute-work-in-jsf-when-and-how-should-it-be-used – BalusC Jan 21 '16 at 09:38
  • Absolutely right that my bean was in SessionScoped although i'm not using the binding attribute on any component. I think I'm just declaring components in the view side and binding their runtime attributes? Following your link I changed the bean to RequestScoped but I still get the same exception. Now you are making me think that my problem has nothing to do with Ajax and possibly a Java / Bean issue? – jay tai Jan 21 '16 at 10:37
  • 1
    MCVE in a more focused question would help http://stackoverflow.com/tags/jsf/info Way too much ambiguity here. No one could reproduce your problem based on information provided so far. – BalusC Jan 21 '16 at 10:42
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/101279/discussion-between-jay-tai-and-balusc). – jay tai Jan 21 '16 at 10:46
  • Please see:http://stackoverflow.com/questions/34925720/primefaces-ajax-not-firing-request-event-from-commandlink-after-page-navigation – jay tai Jan 21 '16 at 13:55

0 Answers0