Thursday, August 27, 2009

ADF Faces (Trinity): af:forEach and af:table...think twice

Rule of thumb: be careful of using af:forEach in af:table rows to generate the options of a select list. Much safer to use getter to get a list and plug into value of f:selectItems (plural), than to use f:selectItem (singular) and use af:forEach to iterate over. af:iterator might work instead of af:forEach, too, but I am not sure.

Also mixed in with this was using forEach's varStatus property...something I have had bad luck with in the past.

Basically what was happening, was this forEach was not even on a part of the screen that was getting rendered, but it was causing components to render multiple times and get all mixed up. Pretty hard to track down.

So in this particular case I would get this doubling when I used the following inside of an af:selectOneChoice...

<af:forEach begin="1"
<f:selectItem itemLabel="#{priorityLoop.index}"

...instead of using someting like the following...

The use-case for this problem was a bit odd, but nothing too bad...

No comments: