4 Replies Latest reply on Sep 17, 2008 6:11 AM by ff fff

    <a4j:repeat > add / remove entries from list

    ff fff Newbie


      i have a list of entries that i iterate over with a4j:repeat.
      Each entry has a commandLink with the possebility to add / remove a new entry.

      In the reRender attribute of the commandLink i reRender the whole list, so the entries are removed / added corretly.So far so good, but...

      Becourse i reRender the whole list any user input made will be lost
      (my commandLink have ajaxSingle=true to prevent validation on add / remove action).

      So my idea was - only update the part that has changed and any user input will be saved.
      So i looked at the a4j:repeat Component and it ajaxKeys attribute - so i can only update the row which is affected.That works pretty good for the remove action but not for the add action.

      I think becourse in the add action i add a entry to list and set the key index to that new index but the repeat dont know that index(becourse it wasnt reRenderd)

      Well do u under stand what i mean and do u see any "clean" solution to that(add action) except writing javascript to save the input values?

      Thx very much,

        • 1. Re: <a4j:repeat > add / remove entries from list
          ff fff Newbie

          Here the code

          <a4j:repeat id="valueList" var="listValue" value="#{configEntity.configurationValueList}" ajaxKeys="#{confManagerBean.keys}">
           <a4j:outputPanel id="listValuePanel">
           <ui:fragment rendered="#{listValue.rendered}">
           <h:message for="configurationEntityListValue" warnClass="message_warn" />
           <div style="float:left; margin-left:10px;">|-</div>
           <!-- works -->
           <a4j:commandLink value="remove (no ajaxkeys)"
           styleClass="resetButton removeItemButton" >
           <f:param name="configurationValueKey" value="#{configEntity.configurationKey}" />
           <f:param name="displayId" value="#{listValue.displayId}" />
           <!-- dont work -->
           <a4j:commandLink value="add entry immediate"
           styleClass="resetButton addItemButton" >
           <f:param name="configurationValueKey" value="#{configEntity.configurationKey}" />
           <h:inputText id="configurationEntityListValue" value="#{listValue.entry}" styleClass="configInput, configInputListEntry">
           <f:attribute name="configKey" value="#{configEntity.configurationKey}" />
           <f:validator validatorId="configurationEntityValidator" />

          removed method:

           for(int i=0; i<list.size(); i++) {
           ConfigurationValueListEntry listEntry = list.get(i);
           String displayId = listEntry.getDisplayId();
           if (displayId.equals(displayIdParam)) {

          add method:
           int reRenderIndex = list.size() -1;

          • 2. Re: <a4j:repeat > add / remove entries from list
            ff fff Newbie

            maybe my post was a bit to complicated, what i really want to do is:

            1) add an entry to a list
            2) reRender the list BUT only the row that was added(leave the rest of the list)

            For removing entries from list - if found a solution with a4j:repat and ajaxKeys attribute, how to get it to work for add action(is it possible at all)?

            A statement on this from a richfaces developer would b really nice.

            THx very much,

            • 3. Re: <a4j:repeat > add / remove entries from list
              Ilya Shaikovsky Master


              2) reRender the list BUT only the row that was added(leave the rest of the list)

              this isn't possible due to very simple reason - imagine ajax responce which contains new row. Where could we insert this content? It's possible only to update some existent DOM nodes (parents).

              • 4. Re: <a4j:repeat > add / remove entries from list
                ff fff Newbie

                Well. i was afraid the answer is that it wouldnt be possible.

                So i have to reRender the whole list for add action?
                The problem is that the list consist of several input fields which will loose the input made by the user on the add action.

                Thats my main problem i got.Any suggestions on this?
                (a solution which comes to my mind is to save the input from the field with javascript and to restore values after dom was updated)

                I was hoping for some richfaces magic like "just use binding" or "use component state saving that and that way" - if theres any possebility to do that(without wriitng own javascript) - pls tell me.

                Thx very much for the quick answer ilya.