Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 717
gohohgle Avatar asked Jun 13 '12 21:06

gohohgle


1 Answers

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?
like image 91
BalusC Avatar answered Sep 18 '22 12:09

BalusC