11 Replies Latest reply on Jun 28, 2010 5:03 AM by ilya_shaikovsky

    Setters not fired after partial rerender

    morgan_david

      My issue: setters on my backing bean are no longer fired after the outputPanel that contains inputs for them is rerendered.

      Simple example:

      <h:selectOneRadio value="#{manager.bool}">
       <f:selectItem itemValue="true" itemLabel="On" />
       <f:selectItem itemValue="false" itemLabel="Off />
       <a4j:support event="onclick" reRender="panel" ajaxSingle="true" />
      </h:selectOneRadio>
      
      <a4j:outputPanel id="panel">
       <h:inputText value="#{manager.firstName}" rendered="#{manager.bool}" />
       <h:inputText value="#{manager.lastName}" rendered="#{manager.bool}" />
      </a4j:outputPanel>
      


      Now once outputPanel is rerendered (thereby either showing or hiding the two inputs) setFirstName and setLastName are no longer fired. The situation is the same regardless of whether the inputs' rendered or disabled properties are set.

      I've tried wrapping the selectOneRadio control with a4j:region but that doesn't appear to alter anything. a4j:log and rich:messages don't show any errors.

      Environment:
      JBoss 4.2.2.GA
      Richfaces 3.1.4
      Seam 2.0.0.GA (if that matters)

      Anybody have any ideas on what's going on or how to fix it? Thanks ahead of time.

        • 1. Re: Setters not fired after partial rerender
          morgan_david

          One more addition: I've dropped phaseTracker.jar in with the war and I am getting output about which phase things are in.

          • 2. Re: Setters not fired after partial rerender
            • 3. Re: Setters not fired after partial rerender
              morgan_david

              I appreciate the response Sergey, but I don't think that the suggestions in that article will help.


              • The value of the inputs aren't dependent on one another; whether some inputs are rendered (or enabled) are dependent on the value of one.
              • The getters aren't affected by the rerender: if firstName is set to "Joe" by some contructor and I then set it to "Bob" via the just rerendered h:inputText after the rerender that change is not reflected after the submit. firstName remains "Joe" and debugging shows that the setFirstName method was never called.
              • This isn't happening with just inputText controls.


                I'll try my best to describe the behavior I'm seeing.

                1. User is presented with a form with multiple elements including radio buttons that toggle a boolean value in the backing bean via a4j:support.
                2. Once one of the radio buttons is clicked the outputPanel is rerendered. Now the controls within that panel are rendered (or enabled) based on the value of the boolean value in the backing bean.
                3. If the boolean is true the controls are rendered.
                4. The user types some values (or selects values) in those new inputs and clicks submit.
                5. During the submit method in the backing bean those fields bound to the rerendered inputs are unchanged (user input has been lost).


                  Again, in my debugging I've seen that the setters on those fields aren't getting called. I've also tried a4j:support (with event="onblur") on these inputs for simple validating to see if the setters are ever called. The setters in this case as well are not called. Once the ajax request is done and things are rerendered the values in these inputs are unchanged.


              • 4. Re: Setters not fired after partial rerender
                morgan_david

                I did a little bit more digging into this and watched the output from phaseTracker very carefully. It appears that after the rerender a subsequent ajax request on any input that was rerendered results in going from the PROCESS_VALIDATIONS directly to RENDER_RESPONSE.

                Now I'm seeing why you suggested I look at that article, Sergey. A binding just might be what I need to do.

                • 5. Re: Setters not fired after partial rerender

                  What id you add <rich:messages /> on the page?

                  • 6. Re: Setters not fired after partial rerender
                    morgan_david

                     

                    "SergeySmirnov" wrote:
                    What id you add <rich:messages /> on the page?

                    I didn't give it an id.

                    Some more information: UPDATE_MODEL_VALUES and INVOKE_APPLICATION are not always skipped. If the entire form is filled out and submitted all 6 phases are gone through.

                    • 7. Re: Setters not fired after partial rerender

                      what if you remove ajaxSingle and wrap selectOneRadio with a4j:region ?

                      • 8. Re: Setters not fired after partial rerender
                        morgan_david

                        No difference.

                        I've made a simple bean and page to test this a little better.

                        Bean (getters and setters omitted for brevity):

                        @Name("simpleBean")
                        public class SimpleBean {
                         private boolean one;
                         private boolean two;
                        }
                        


                        Page:
                        <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                        <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
                        xmlns:f="http://java.sun.com/jsf/core"
                        xmlns:h="http://java.sun.com/jsf/html"
                        xmlns:a4j="http://richfaces.org/a4j">
                        
                        <body>
                         <h:form>
                         <h:selectOneRadio value="#{simpleBean.one}">
                         <f:selectItem itemValue="true" itemLabel="On" />
                         <f:selectItem itemValue="false" itemLabel="Off" />
                         <a4j:support event="onclick" reRender="test" />
                         </h:selectOneRadio>
                        
                         <a4j:outputPanel id="test" layout="block">
                         <h:selectOneRadio value="#{simpleBean.two}" rendered="#{simpleBean.one}">
                         <f:selectItem itemValue="true" itemLabel="On" />
                         <f:selectItem itemValue="false" itemLabel="Off" />
                         <a4j:support event="onclick" reRender="test2" />
                         </h:selectOneRadio>
                         <a4j:outputPanel id="test2" layout="block">
                         <h:outputText value="Hello" rendered="#{simpleBean.two}" />
                         </a4j:outputPanel>
                         </a4j:outputPanel>
                         </h:form>
                        </body>
                        </ui:composition>
                        


                        Click 'On', 'On'. 'Hello' won't render because simpleBean.two is still false; it's setter was never called.

                        • 9. Re: Setters not fired after partial rerender
                          morgan_david

                          Now do I feel stupid. Apparently the issue was because my bean was in Seam's conversation scope. I forgot @Begin(join=true) on the relevant methods. Once I added those things started to work.

                          Thanks again for your help Sergey.

                          • 10. Re: Setters not fired after partial rerender
                            erdyes

                            Hi David, i have the same problem. But i use richfaces, i dont use seam. Do you have any suggestion?

                             

                            Thanks for any help,

                            • 11. Re: Setters not fired after partial rerender
                              ilya_shaikovsky

                              please post concrete problem description. check carefully from the beginning that rendered or disabled properties of components held in beans which leaves longer than request.