2 Replies Latest reply on Sep 24, 2010 10:21 AM by msanders-at

    a4j & jsf (re)rendering with dynamic ids - Is this Possible?

    msanders-at

      I have a list of items that I iterate over to create a list of selectBooleanCheckboxes and then elsewhere in the page I re-iterate over them to create corresponding content areas that I want to render and then re-render whenever the checkbox is checked.  I've tried two methods but I can't seem to get either to work.

       

      1.  This method doesn't work because (I think) the ID is generated at "build time" rather than "render time" so the id for each outputPanel is always "wrapper-"

       

      {code}<h:form id="searchForm">


          <a4j:repeat value="#{searchFormReferenceBean.selectItems}" var="select" rowKeyVar="rowNum">


              <h:selectBooleanCheckbox>

                  <a4j:support event="onclick" reRender="wrapper-#{rowNum}"/>


              </h:selectBooleanCheckbox><label>#{select.value}</label>


          </a4j:repeat>


      </h:form>

       


      <a4j:repeat id="iterator" value="#{searchFormReferenceBean.selectItems}" var="make" rowKeyVar="rowNum">

          <a4j:outputPanel id="wrapper-#{rowNum}">

              #{rowNum} - #{currentTime}<br/>


          </a4j:outputPanel>

      </a4j:repeat>{code}

       

       

      2. The second method I tried doesn't work either.  I've tried to match up the rowNumbers here (doesn't have to be the row num for what I care, could be the selectItem value or something else if needed) since I'm iterating over the same list.  However I get error messages saying "14:07:05,215 WARN  [org.ajax4jsf.context.AjaxContext] () Target component for id iterator:0:wrapper not found" each time the a4j:support fires which obviously means that nothing is going to get reRendered.

       

      {code}<h:form id="searchForm">


          <a4j:repeat value="#{specialsSearchFormReferenceBean.makeSelectItems}" var="select" rowKeyVar="rowNum">

       

              <h:selectBooleanCheckbox>


                  <a4j:support event="onclick" reRender="iterator:#{rowNum}:wrapper"/>


              </h:selectBooleanCheckbox><label>#{select.value}</label>


          </a4j:repeat>


      </h:form>

       


      <a4j:repeat id="iterator" value="#{specialsSearchFormReferenceBean.makeSelectItems}" var="make" rowKeyVar="rowNum">


          <a4j:outputPanel id="wrapper">


              #{rowNum} - #{currentTime}<br/>


          </a4j:outputPanel>


      </a4j:repeat>{code}

       

       

      Could someone please instruct me on the best way to accomplish this?

       

      I'm not opposed to using the selectManyCheckbox either if needed, but I don't see how one would attach the unique a4j:support events to each item in the f:selectItems list.  However I do not think that switching the iteration to c:forEach is an option because I may need to re-render both of the "iterations" and they could possibly change in length.

       

      -Marshall