简体   繁体   中英

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

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?

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM