6 Replies Latest reply on Jun 2, 2010 9:59 AM by Ilya Shaikovsky

    Developed component rerender problem

    Igor Grinfeld Newbie

      Yesterday, I've write test page to new component I've developed. It represents list of week days and allows to select several of days. Value of component is bit mask, storing days selected. In the beginning, I wrote simple page displaying the component check if it is updated when one of the days is clicked. I could see visually that client side was updated and debug mode helped me to see that the value is updated too. After that, I've

      wrote more complicated test. It has additional component, 'h:inputText' and managed bean that links between components. It supposed the with a4j:support I can seen that days selections in new component will be updated when value in input changes and value in input will change if if one of the days is clicked. The test, based on livedemo for a4j:outputPanel example, works only in one direction. It updates days component when I change the value of input, but input is not updated when I click one of the days, although value of days component is updated. Can anybody tell me if the problem is in test page or in component definition.


      Test page:


      <?xml version="1.0" encoding="ISO-8859-1" ?>
      <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
      <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
      <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
      <%@ taglib uri="http://sintecmedia.com/richComponents" prefix="my"%>
      <html xmlns="http://www.w3.org/1999/xhtml" 
           <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
           <title>Insert title here</title>
      <a4j:outputPanel layout="block">
           <a4j:outputPanel id="buttons" layout="block">
                <my:weekDaysButtons value="#{testWeekDaysBean.days}" > 
                     <a4j:support event="onchange" reRender="testValue" />
           <a4j:outputPanel id="testValue" layout="block">
                <h:inputText value="#{testWeekDaysBean.days}">
                     <f:validateLength maximum="1"/>
                     <a4j:support event="onkeyup" reRender="buttons" />


      testWeekDaysBean( request scope):


      package beans;
      import com.sintecmedia.components.component.UIWeekDaysButtons;
      import com.sintecmedia.components.event.DaySelectedEvent;
      public class WeekDaysButtonsTestBean {
           private int dayFlags = 3;
           public int getDays() { return dayFlags; }     
           public void setDays( int dayFlags ) {
                this.dayFlags = dayFlags;
           protected void updateDay( int index, Boolean val ) {
                if( val ) {
                     setDays( getDays() & ~UIWeekDaysButtons.DAY_MASKS[ index ] );
                } else {
                     setDays( getDays() | UIWeekDaysButtons.DAY_MASKS[ index ] );

      Component definition attached

        • 1. Re: Developed component rerender problem
          Nick Belaevski Master



          Does your component has "onchange" attribute? Check that generated HTML code contains JS code of a4j:support (A4J.AJAX.submit* method invocation).

          • 2. Re: Developed component rerender problem
            Igor Grinfeld Newbie

            I didn't declared onchange attribute explicitly, but it is exist in html_control_events included entity that I use. I didn't find onchange attribute or A4J.AJAX.submit* invocation in source. Here is the source of problematic 'buttons' div and its server side JSP piece. Can you see why onchange is not inserted in source?

            <div id="buttons">
             <form id="j_id_jsp_1568918406_3" name="j_id_jsp_1568918406_3" method="post" 
            action="/testComponents/testWeekDaysButtons.jsf" enctype="application/x-www-form-urlencoded">
             <div id="j_id_jsp_1568918406_3:j_id_jsp_1568918406_4" name="j_id_jsp_1568918406_3:j_id_jsp_1568918406_4">
             <table cellpadding="0" cellspaceing="0" class="daysOfTheWeekSelector">
            <td class="selected" onclick="changeSelection(this,0)">Sn</td>
            <td class="selected" onclick="changeSelection(this,1)">M</td>
            <td class="unselected" onclick="changeSelection(this,2)">Tu</td>
            <td class="unselected" onclick="changeSelection(this,3)">W</td>
            <td class="unselected" onclick="changeSelection(this,4)">Th</td>
            <td class="unselected" onclick="changeSelection(this,5)">F</td>
            <td class="unselected" onclick="changeSelection(this,6)">St</td>
            <script type="text/javascript"><!--
            new Richfaces.DaySelector( 'j_id_jsp_1568918406_3:j_id_jsp_1568918406_4', 
            'parameters':{'j_id_jsp_1568918406_3:j_id_jsp_1568918406_4':event.memo.dayIndex} ,
            'containerId':'j_id_jsp_1568918406_0'} ); 
            return false;
            <input type="hidden" name="j_id_jsp_1568918406_3_SUBMIT" value="1" />
            <input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" 
            value="oUVWRKHTp9OPmSPWERatCXhihcD6B1XVpzUXDhrvs81LY6SjDpEdEFNKmopFIRg+6glSq8qntpZpCG05kRL+j56auZCaqs3BWoxAlXBX29hOQ2nWfr2jsg==" />


            At server side:


            <a4j:outputPanel id="buttons" layout="block">
            <my:weekDaysButtons value="#{testWeekDaysBean.days}"
                 <a4j:support event="onchange" reRender="testValue" />
            • 3. Re: Developed component rerender problem
              Nick Belaevski Master



              Your component is not rendering "onchange" handler, that's the problem. You should add the code to renderer template that writes this attribute or passes it into JS constructor call.

              1 of 1 people found this helpful
              • 4. Re: Developed component rerender problem
                Mike Kienenberger Newbie

                This sounds very similar to the problem I am having where reRendering an h:inputText doesn't pull the value from the model, but instead reRenders the submitted value of the h:inputText.


                component.resetValue()  has no effect for a4j reRender



                If you force the entire page to rerender (non-ajax), does the value show up correctly?

                Have you used the debugger to determine if the inputText model bean has the correct value?  If it does, you're probably hitting the same situation.

                • 5. Re: Developed component rerender problem
                  Igor Grinfeld Newbie

                  Hi Nick, do you mean that I should define something like this:


                  <table cellpadding="0" cellspaceing="0" onchange="#{component.attributes['onchange']}">...</table>


                  to make ' a4j:support event="onchange" ' working.



                  • 6. Re: Developed component rerender problem
                    Ilya Shaikovsky Master

                    yes.. thats the way. The component should encode attribute in some way in order a4j:support attachment to be possible. Simple check for if you implemented encoding properly - just define <c:yourCustomComponent onchange="alert()"/> in your test and if you able to see JS executed - things are ok and you should be able to attach support to the event also.