Property set by f:setPropertyActionListener becomes null on subsequent ajax request

723 views Asked by At

Folks,

I'm getting a strange behavior with a JSF ajax render event. I've a h:datatable with one action column like this example:

<h:panelGroup id="myPanel">
                                <h:dataTable value="#{myController.data}" var="element" rendered="#{not empty myController.data}">
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="Test"/>
                                    </f:facet>
                                    <h:outputText value="#{element.status}"/>
                                </h:column><h:column>
                                    <f:facet name="header">
                                        <h:outputText value="Action"/>
                                    </f:facet>
                                    <h:form>


                                        <h:commandButton id="generateXML" value="Generate" onclick="openModal('#confirmModal')">
                                            <f:ajax execute="@this"/>
                                            <f:setPropertyActionListener for="generateXML" target="#{myController.selectedElement}" value="#{element}" />
                                        </h:commandButton>


                                    </h:form></h:column></h:datatable></h:panelGroup>

And I've one modal that call the action method on myController. The main part: (Note the modal and datatable forms are distincts)

 <h:commandButton value="Confirm" action="#{myController.create()}" onclick="$('#confirmModal').modal('hide');">
                    <f:ajax execute="@this" render=":myPanel"/>
                </h:commandButton>

The strange behavior:

At the first time that I execute this code, this works correctly, the action of the f:setPropertyActionListener and the render that updates the table data. But If I try to execute the same action again, the f:setPropertyActionListener does not work, giving me a NPE. If I reload the page, it works.

What is happening here?

EDIT

The part that is null is the #{myController.selectedElement}. This ajax is not executed anymore after the rerender.

My Controller code:

@ManagedBean
@ViewScoped
public class MyController implements Serializable {

   private Object element;

   // This method is called only once. If render the panelGroup (render=":myPanel")
   public void setSelectedJob(final XmlJob selectedJob) {
     this.selectedJob = selectedJob;
   }

}
0

There are 0 answers