Reputation: 744
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?
Upvotes: 1
Views: 888
Reputation: 1109372
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>
Upvotes: 2