How to use <ui:include> inside a <h:dataTable>?

心已入冬 提交于 2019-12-23 12:54:08

问题


I want to inlude <ui:include> one page dynamically several times.

Code:

<h:dataTable ..>
    <h:column>
        <ui:include  src="#{create_page}">
    <h:column>
<h:dataTable>

Now when I submit it persists only the last inlude. It remembers only the values for the last included page. I want unique entity object in each create_page. How can I do that?


回答1:


The <ui:include> is as being a tag handler executed during view build time, while the <h:dataTable> is as being an UI component executed during view render time. This means that the <ui:include> is executed only once before the <h:dataTable> and thus not during the iteration. You effectively end up with exactly the same include source in every row. When the form is submitted the rows are processed one by one until the last row, that's why you effectively end up with the values of the last row.

There are basically 2 ways to solve this:

  1. Use <c:forEach> instead of <h:dataTable>, this runs also during view build time.

  2. Use a tag file or a composite component instead of <ui:include>, this runs also during view render time.

Either way, you also need to ensure that the input values are bound to the object behind the var attribute of the datatable, not to one and same backing bean property.

See also:

  • JSTL in JSF2 Facelets... makes sense? (the <ui:include> falls in the same category as JSTL)
  • When to use <ui:include>, tag files, composite components and/or custom components?


来源:https://stackoverflow.com/questions/11023331/how-to-use-uiinclude-inside-a-hdatatable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!