2 Replies Latest reply on Sep 14, 2009 6:31 AM by JLuis -

    ajaxKeys example

    JLuis - Newbie

      This sample code doesn't work for me.
      Could somebody help me to fix it? my try's weren't successful...

      <table>
       <a4j:repeat value="#{repeatBean.numbers}" var="rec" rowKeyVar="rowIndex" ajaxKeys="#{repeatBean.rowsToUpdate}">
       <tr>
       <td width="20px">
       <h:outputText id="num" value="#{rec.number}" />
       </td>
       <td>
       <a4j:commandLink value="-" reRender="num" actionListener="#{repeatBean.decrease}">
       <a4j:actionparam name="rowIndex" value="#{rowIndex}"
       assignTo="#{repeatBean.updatedRow}" />
       </a4j:commandLink>
       /
       <a4j:commandLink value="+" reRender="num" actionListener="#{repeatBean.increase}">
       <a4j:actionparam name="rowIndex" value="#{rowIndex}"
       assignTo="#{repeatBean.updatedRow}" />
       </a4j:commandLink>
       </td>
       </tr>
       </a4j:repeat>
      </table>
      
      import java.util.ArrayList;
      import java.util.HashSet;
      import java.util.List;
      import java.util.Set;
      
      import javax.annotation.PostConstruct;
      import javax.faces.event.ActionEvent;
      
      public class RepeatBean {
      
       private List<NumberBean> numbers;
       private Set<Integer> rowsToUpdate;
       private Integer updatedRow;
      
       @PostConstruct
       public void init() {
       numbers = new ArrayList<NumberBean>();
       numbers.add(new NumberBean());
       numbers.add(new NumberBean());
       numbers.add(new NumberBean());
       numbers.add(new NumberBean());
       numbers.add(new NumberBean());
       rowsToUpdate = new HashSet<Integer>();
       updatedRow = 0;
       }
      
       public List<NumberBean> getNumbers() {
       return numbers;
       }
      
       public void setNumbers(List<NumberBean> numbers) {
       this.numbers = numbers;
       }
      
       public Set<Integer> getRowsToUpdate() {
       return rowsToUpdate;
       }
      
       public Integer getUpdatedRow() {
       return updatedRow;
       }
      
       public void setUpdatedRow(Integer updatedRow) {
       this.updatedRow = updatedRow;
       }
      
       public void increase(ActionEvent event) {
       rowsToUpdate.clear();
       numbers.get(updatedRow).increase();
       rowsToUpdate.add(updatedRow);
       }
      
       public void decrease(ActionEvent event) {
       rowsToUpdate.clear();
       numbers.get(updatedRow).decrease();
       rowsToUpdate.add(updatedRow);
       }
      
      }
      
      public class NumberBean {
      
       private Integer number;
      
       public NumberBean() {
       number = 10;
       }
      
       public Integer getNumber() {
       return number;
       }
      
       public void setNumber(Integer number) {
       this.number = number;
       }
      
       public void increase() {
       ++number;
       }
      
       public void decrease() {
       --number;
       }
      
      }