Skip to main content

c:forEach creates inconsistent behaviour for components with id

1 reply [Last post]
nithril
Offline
Joined: 2007-02-09
Points: 0

Hello,

Mojarra 2.1.12
Primefaces 3.4-RC1

If have a c:forEach statement :

        <c:forEach items="#{component.components}" var="item">
                <ui:include src="#{item.componentUri}">
                    <ui:param name="component" value="#{item}"/>
                </ui:include>
        </c:forEach>
  • "#{component.components}" contains more than one element.
  • A parent of "c:forEach" contains a binding.
  • All ui:include contain differents jsf fragment with a form and an id attribute

The use case is the following.

1) The user loads the page :

  • ForEachHandler.apply calls "ComponentSupport.setNeedUniqueIds(ctx, true)" so children's id are generated even if forEach's children contain id.
  • "ComponentTagHandlerDelegateImpl.apply" creates the children's components with a generated id.

2) The user clicks on an ajax link :

  • The javax.faces.source attribute contains a generated id
  • the restore view phase is executed
  • Because of the bidding, components already exists. "ComponentTagHandlerDelegateImpl.apply" finds the component, calls "ComponentTagHandlerDelegateImpl.doExistingComponentActions" which erases the generated id with the id set as xml attribute.

=> There is a mismatch between the javax.faces.source attribute and the id inside the tree
=> The action handler is never fired

Is this a bug? Or my use case is a bad use of jsf?

Why c:forEach generates id even when id attribute is set? If there is a duplicated id exception, does it not the developer responsability to resolve this case ?

Thanks,

Nicolas

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rogerkeays
Offline
Joined: 2005-06-15
Points: 0

Dynamic includes is not well supported by JSF. You get all sorts of problems. You really want to try to refactor your templates so there is no dynamic include. This article might also help you understand c:forEach and the inherent problems it has:

http://www.ninthavenue.com.au/c:foreach-vs-ui:repeat-in-facelets