1

I added postAddtoView event listener to below component. I was expecting the orderView.populateForm listener method is being called once during creation of the initial view (https://javaserverfaces.java.net/nonav/docs/2.2/javadocs/javax/faces/event/PostAddToViewEvent.html ). For any postback call where view is restored I do not expect a new component instance is added to view. Hence no event to fire.

However, event listener method is being called for each postback call.

      <h:form id="orderForm">
        <p:panelGrid id="attributePanel" columns="#{orderView.numberOfGridColumns}">
            <f:event type="postAddToView" listener="#{orderView.populateForm}" />
        </p:panelGrid>

        <p:commandButton  ajax="true" value="Create" process="@form" update="@form"/>
    </h:form>

OrderView is a view scoped CDI bean. As far as I understand view scoped beans are stored in the partial view state and by default partial view state saving is enabled. (BalusC gives a nice explanation here about the issue Should PARTIAL_STATE_SAVING be set to false?) To see it has an effect, I disabled/enabled partial state saving. It did not help.

Thanks in advance. PS: I am running on Mojarra 2.2.12/ Glassfish 4.1

Community
  • 1
  • 1
Ali Alagoz
  • 21
  • 6
  • 1
    Which of those is most helpful in understanding and answering your problem http://stackoverflow.com/q/31890433 or http://stackoverflow.com/q/14911158? To the point, component instances are not at all stored in view state. – BalusC Sep 12 '16 at 11:17
  • I think http://stackoverflow.com/q/14911158 is quite helpful. I did not know "JSF component tree will be produced" even for postback calls. Somehow I had the understanding that view state also keeps the component tree structure. (Clearly this understanding is wrong). On the other hand JSF 2.0 spec says (https://javaserverfaces.java.net/nonav/docs/2.1/javadocs/javax/faces/event/PostAddToViewEvent.html) if it is a postback call and phase is restoreView then event listener method is not called. Does this mean between 2.1 and 2.2. versions there is a change in event framework? – Ali Alagoz Sep 12 '16 at 12:07
  • Apparently postback has created a new view during render response (e.g. navigation). – BalusC Sep 12 '16 at 14:22
  • 1
    postback is a ajax call and does not navigate to another view. New view is created during restoreView phase. This was the point confusing me. I was not expecting yet another event to be fired. During creation same view scoped bean is called. – Ali Alagoz Sep 12 '16 at 16:34

0 Answers0