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>
| </c:forEach>
public String bar(Long index) {
| log.info(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>
| </ui:repeat>
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.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3990142#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...