6 Replies Latest reply on Jun 23, 2009 11:13 AM by nille m

    Problem with custim IDs in within dataTable /S subTable

    nille m Newbie

      Hi,

      as stated in the subject, I have a problem with custom IDs in a subTable.

      The (sub)table contains 19 rows and 7 column and therefore 133 field. Each field is represented by an object in a 2-dimensional array kept in the backing bean. The subTable 'value' keeps the rows (and iterates through them) and and 'rich:columns' gets the the appropriate (1-dimensional) array of fields from the mentioned 2-dimensional array and displays the information stored within each object of the array. Each object has a property 'identifier' which should be used for the 'id' attribute of eg 'h:outputText' and contains just the prefix'id_' followed by the index of the field starting at '0' to '132'.

      <h:form id="monatsberichtUnfaelleForm">
      ....
      <rich:dataTable value="#{monatsberichtReportAction_Tarifbereiche.listWithNumberOfSubtables}" var="listHeaders" id="Monatsbericht_Tarifbereiche_MainTable">
      ...
      <rich:subTable value="#{monatsberichtReportAction_Tarifbereiche.getReportTable().descriptions}" var="tarifbereicheTableRow" border="0" id="monatsberichtValuesSubTable">
       <rich:column styleClass="#{tarifbereicheTableRow.styleClass}">
       <h:outputLink value="#{tarifbereicheTableRow.linkTarget}">
       <h:outputText value="#{tarifbereicheTableRow.linkName}"/>
       </h:outputLink>
       </rich:column>
       <rich:column styleClass="#{tarifbereicheTableRow.styleClass}">
       <h:outputText value="#{tarifbereicheTableRow.description}"/>
       </rich:column>
       <rich:columns value="#{monatsberichtReportAction_Tarifbereiche.getReportTable().getArrayWithFieldValues(tarifbereicheTableRow.mappedToValuesRowId)}" var="field" border="0" index ="ind3" styleClass="#{field.getStyleClass()}" colspan="#{field.getColspan()}" visible="#{!field.isHidden()}">
       <h:inputText value="#{field.fieldIntegerValue}" id="#{field.identifier}_test">
       <a4j:support event="onchange" ajaxSingle="false" action="#{monatsberichtReportAction_Tarifbereiche.calculateSums(0, tarifbereicheTableRow.mappedToValuesRowId, ind3)}" reRender="id_6, id_126"/>
       </h:inputText>
       <h:outputText value="#{field.identifier}"/>
       <h:outputText value="#{field.fieldIntegerValue}" id="#{field.identifier}" />
       </rich:columns>
      </rich:subTable>
      



      If I display the 'identifier' property in a 'h:outputText' element the correct value is displayed, see above or:
      <h:outputText value="#{field.identifier}"/>


      If I use this values in the 'id' attribute, each row contains IDs from 'id_0' to 'id_6' with some prefix generated by the IDs of the parent elements. The have the following pattern:

      <input id="monatsberichtUnfaelleForm:Monatsbericht_Tarifbereiche_MainTable:monatsberichtValuesSubTable:0:id_0_test"...
      <span id="monatsberichtUnfaelleForm:Monatsbericht_Tarifbereiche_MainTable:monatsberichtValuesSubTable:0:id_0"...
      ..
      <input id="monatsberichtUnfaelleForm:Monatsbericht_Tarifbereiche_MainTable:monatsberichtValuesSubTable:0:id_1_test"...
      <span id="monatsberichtUnfaelleForm:Monatsbericht_Tarifbereiche_MainTable:monatsberichtValuesSubTable:0:id_1"...
      ..
      <input id="monatsberichtUnfaelleForm:Monatsbericht_Tarifbereiche_MainTable:monatsberichtValuesSubTable:0:id_2_test"...
      <span id="monatsberichtUnfaelleForm:Monatsbericht_Tarifbereiche_MainTable:monatsberichtValuesSubTable:0:id_2"...
      ...
      <input id="monatsberichtUnfaelleForm:Monatsbericht_Tarifbereiche_MainTable:monatsberichtValuesSubTable:18:id_0_test"...
      <span id="monatsberichtUnfaelleForm:Monatsbericht_Tarifbereiche_MainTable:monatsberichtValuesSubTable:18:id_0"...
      ..
      <input id="monatsberichtUnfaelleForm:Monatsbericht_Tarifbereiche_MainTable:monatsberichtValuesSubTable:18:id_1_test"...
      <span id="monatsberichtUnfaelleForm:Monatsbericht_Tarifbereiche_MainTable:monatsberichtValuesSubTable:18:id_1"...
      ...
      <input id="monatsberichtUnfaelleForm:Monatsbericht_Tarifbereiche_MainTable:monatsberichtValuesSubTable:18:id_2_test"...
      <span id="monatsberichtUnfaelleForm:Monatsbericht_Tarifbereiche_MainTable:monatsberichtValuesSubTable:18:id_2"...
      ...
      

      The reason I need 'my unique' IDs is that I need to update some fields (h:outptText elements) of the table via AJAX. Updating the whole table works fine but takes far too long.

      Maybe...very likely I`m doing something wrong...

      Note: I used #{field.identifier} both for a h:inputText and h:outputText. To avoid 'duplicateId' error messages a Concatenated '_test' to the 'id' attribute of the h:inputText.

      Thanks a lot in advance,

      Kind Regards,
      nille

        • 1. Re: Problem with custim IDs in within dataTable /S subTable
          Ilya Shaikovsky Master

          Starting from the beginning(main design goal of that thread:) ) - you should deal with just ajaxKeys attribute of the table in order to get separate cells update functionality to work. And the framework will do the job for you.

          • 2. Re: Problem with custim IDs in within dataTable /S subTable
            nille m Newbie

            Hi,

            first: thanks for your reply and the hint =).

            I tried the 'ajaxKeys' attribute, but got it only half working. In the bean within the method called by the Ajax request I put the first and last line of the subTable in a hash which is used by 'ajaxKeys'

            ...
            <rich:subTable value="#{monatsberichtReportAction_Tarifbereiche.getReportTable().descriptions}" var="tarifbereicheTableRow"
            id="monatsberichtValuesSubTable" ajaxKeys="#{monatsberichtReportAction_Tarifbereiche.rowsToUpdate}">
            ...
            


            ...
            /* Add the last row (holding the sums) to the set of rows which should be updated */
            rowsToUpdate.add(reportTables[0].getDescriptions().length-1);
            rowsToUpdate.add(0);
            ...
            


            Unfortunately, only the last 'cell' (identified by '...id_6') of the specified rows is updated. This is a part of the response:

            <span class="rich-messages-label"></span></dt></dl>
            
            <span id="monatsberichtUnfaelleForm:Monatsbericht_Tarifbereiche_MainTable:monatsberichtValuesSubTable:0:id_6">210</span>
            <span id="monatsberichtUnfaelleForm:Monatsbericht_Tarifbereiche_MainTable:monatsberichtValuesSubTable:18:id_6">4565</span>
            
            <meta name="Ajax-Update-Ids" content="monatsberichtUnfaelleForm:j_id111,monatsberichtUnfaelleForm:Monatsbericht_Tarifbereiche_MainTable
            :monatsberichtValuesSubTable:0:id_6,monatsberichtUnfaelleForm:Monatsbericht_Tarifbereiche_MainTable:monatsberichtValuesSubTable
            :18:id_6" /><span id="ajax-view-state"><input type="hidden" name="javax.faces.ViewState" id="javax.faces
            .ViewState" value="j_id4" /></span><meta id="Ajax-Response" name="Ajax-Response" content="true" />
            


            Do I have to specify more than just the rows?

            Kind regards,
            nille

            • 3. Re: Problem with custim IDs in within dataTable /S subTable
              Ilya Shaikovsky Master

              add reRender as shown at http://livedemo.exadel.com/richfaces-demo/richfaces/repeat.jsf to the elements inside columns which need to be updated. ajaxKeys and reRendee works as two axis to locate the component to be updated :)

              • 4. Re: Problem with custim IDs in within dataTable /S subTable
                nille m Newbie

                Perfect!

                Thanks a lot. =)...Exactly what I needed.

                Kind regards,
                nille

                • 5. Re: rich:subTable - Possible bug.
                  Alireza Salimi Newbie

                  I checked livedemo, subTable has not been embedded into a column,
                  take a look again:


                  [uards,
                  nille

                  • 6. Re: Problem with custim IDs in within dataTable /S subTable
                    nille m Newbie

                    Hi,

                    did it not work four you? You just have to use 'ajaxKeys' and the 'reRender'. As ilya_shaikovsky said it's like y-axis and y-axis. In my case I used

                    <rich:subTable value="#{monatsberichtReportAction_Tarifbereiche.getReportTable().descriptions}" var="tarifbereicheTableRow" id="monatsberichtValuesSubTable" ajaxKeys="#{monatsberichtReportAction_Tarifbereiche.rowsToUpdate}" rowKeyVar="rowCounter">
                    ...
                    <a4j:support event="onchange" ajaxSingle="true" reRender="id_0,id_1,id_2,id_3,id_4,id_5,id_6".../>
                    ...
                    


                    In the method called by the 'a4j:support' tag I update the Set with rows used by the 'ajaxKeys' attribute. Works like a charm.

                    Kind regards,
                    nille