1

I am trying to allocate id from backing bean to div element using below code:

<c:forEach var="item" items="#{backingBean.dataModel}">
<t:div id="xyz_#{item.id}" forceId="true" forceIdIndex="false" title="#{item.name}" style="display:none">
    <ui:include src="#{item.view}">
        <ui:param name="id" value="#{item.id}" />
        <ui:param name="model" value="#{item.model}" />
    </ui:include>
</t:div>
</c:forEach>

When page is getting loaded for the first time, it assigns correct id as inferred from backing bean. When I refresh the section of page with this code, it do not call getId method of backing bean but calls getView, getModel correctly. As a result, div has incorrect Id.

It might the case that div id is allocated prior to c:forEach execution. How do I enforce div to use Id from backing bean when it is inside c:forEach?

A.G.
  • 734
  • 2
  • 8
  • 27
  • How do you refresh the section? Ajax? – Adrian Mitev Oct 10 '12 at 09:54
  • Yes. I am using a4j:jsfunction render attribute to refresh the section – A.G. Oct 10 '12 at 10:31
  • 1
    I can't recommend you a proper solution but the problem here is that c:forEach is a tag handler, not a component - more info about that could be found here - http://www.ninthavenue.com.au/blog/c:foreach-vs-ui:repeat-in-facelets – Adrian Mitev Oct 10 '12 at 11:06
  • Yes. I have gone through this doc earlier too. I can't use ui:repeat as well because ui:include will not work in that case. Thanks anyways. – A.G. Oct 10 '12 at 12:03

1 Answers1

2

The id (and binding) attributes of JSF UI components are evaluated during view build time (when the JSF component tree is built for the first time), not during view render time nor during future reuse of the very same JSF component tree in subsequent postbacks to the same view.

I'm not exactly sure why you're approaching it with a <t:div> like that. It would make more sense to use a plain HTML <div> in this particular case.

<c:forEach var="item" items="#{backingBean.dataModel}">
    <div id="xyz_#{item.id}" title="#{item.name}" style="display:none">
        <ui:include src="#{item.view}">
            <ui:param name="id" value="#{item.id}" />
            <ui:param name="model" value="#{item.model}" />
        </ui:include>
    </div>
</c:forEach>

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks a lot BalusC! This is perfect answer. May be due to too much of attempts to resolve this, I was not thinking of using plan html tag. I was concentrating more on forEach and include. This is accepted as answer. Thanks once again. You save my day! – A.G. Oct 11 '12 at 04:59