2 Replies Latest reply on Mar 4, 2011 10:04 AM by Some Kid

    reRender does  not work after the value of the backing bean field is changed

    Some Kid Newbie

      Hello,

      I have a seam/richfaces3.3.1 application and I'm having a problem rerendering a field after the value of the backing bean field is changed.

      Here's an example demonstrating my problem.

       

      Test.xhtml

       

      <!DOCTYPE compositionPUBLIC "-//W3C//DTDXHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
          xmlns:s="http://jboss.com/products/seam/taglib"
          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:rich="http://richfaces.org/rich"
          xmlns:a4j="http://richfaces.org/a4j"
          template="layout/template.xhtml">

      <ui:define name="body">
                     <h:form >
                     <rich:panel >
                     <h:panelGrid>
                     <s:div>
                     <s:decorate id="alarmLocationField"template="layout/editLongLabel.xhtml">
                            <ui:define name="label">First Field</ui:define>
                            <h:inputTextarea id="first" value="#{test.first}"  valueChangeListener="#{test.listen2Me}"

                                   required="true"   immediate="true" >
                            <a4j:support event="onblur" reRender="firstField" bypassUpdates="true"ajaxSingle="true" />   
                            </h:inputTextarea>
                            <a4j:commandButton value="Test" action="#{test.setTestCode()}" reRender="firstField,secField" ajaxSingle="true"

                                oncomplete=" alert('I am back');"   />
                            </s:decorate>
                           
                           
                     <s:decorate id="secField" template="layout/editLongLabel.xhtml">
                            <ui:define name="label">Second Field</ui:define>
                            <h:inputTextarea id="second" value="#{test.second}" 
                                   required="true"   immediate="true" >
                            </h:inputTextarea>
                     </s:decorate>                      
                           
                     </s:div>
                     </h:panelGrid>
                     </rich:panel>
                     </h:form>
      </ui:define>
      </ui:composition>

       

       

       

       

       

      And here's the bean

       

      TestBean.java

       

      @Name("test")
      publicclass TestBean
      {
        private String first;
        private String second;

       

        public String getName() {
             return second;
        }

        public void setSecond(String second) {
             this.second= second;
        }

        public String getFirst() {
                return first;
        }
             
         public void setFirst(String first)
         {
             this.first= first;
         }
             
         public String setTestCode()
         {
             setFirst("new code");
             setSecond("new name");
             return"";
         }
             
          public void listen2Me(ValueChangeEventevent)
          {
             System.out.println("I'm in listen2Me" + event.getNewValue());
          }
      }

       

       

       

      The problem is that if I type a text in field "first" and click "Test" I expect the following to happen:

      1. The function of the eventChangeListener is executed
      2. The values of fields "first" and "second" are changed
      3. UI component values are rerendered with the new ones - "new code" and "new name"

       

      What happens however is:

      1. The function of the eventChangeListener is executed
      2. The values of fields "first" and "second"  are changed
      3. Only the "second" field is reRendered with the new value "new name".

       

      After some debugging I found out that the following line

       

      <a4j:support event="onblur" reRender="firstField" bypassUpdates="true"ajaxSingle="true" />   

       

       

      is the reason for the first field keeping the value that was typed instead of reRendering the new value "new code". If I remove that line, however, the eventChangeListener function is not invoked and I have important functionality there that needs to be executed  .

       

      Is there a way of reRendering a control's value if the onblur event has done reRendering as in this example?

      Thanks.