0 Replies Latest reply on Nov 30, 2006 11:37 AM by anti spart

    Extended EL and JSTL c:forEach. Plus, setting a component's

    anti spart Newbie

      I'm trying to iterate over a list and pass the index from each item in that list to an actionlistener method. I've tried two methods - ui:repeat and c:forEach, but both approaches have drawbacks.

      Note, I also need to have an html "id" attribute assigned to each (a4j:commandLink) dynamically - via the EL. This is so that my javascript can reference these elements later.

      <c:forEach items="${personList}" var="person">
       <a:commandLink id="person#{person.index}" action="#{foo.bar(person.index)}">#{person.name}</a:commandLink>

      public String bar(Long index) {
       return null;

      With c:forEach, the html "id" of each <a:commandLink> component is set properly - it sends up being id="testForm:person1" ... id="testForm:personN" . But, the bar() method's "index" is properly is null instead of being set to the value passed in with #{person.index}

      Now with ui:repeat:

      <ui:repeat value="${personList}" var="person">
       <a:commandLink id="person#{person.index}" action="#{foo.bar(person.index)}">#{person.name}</a:commandLink>

      In the 2nd case, the bar() method's "index" is properly set to the value passed in with #{person.index}. But, the html "id" of the <a:commandLink> is not set (instead it is something like "testForm:j_id62:1:person").

      I've found that html "ids" cannot be set with EL on components within <h:dataTable> or <ui:repeat>. But, the html "id" can be set on a component that is inside a <c:forEach> as in the 1st example.

      So, this is a case where one solution works for one thing but not for the other and vice versa. I would greatly appreciate any advice. Thanks.