I have a table where one of it’s columns contains a dropdown list (HtmlSelectItems component).
For any given row in this table, I want to be able to show or hide the dropdown at runtime, based on specific application conditions.
My solution in this case was to use the component’s pre-render event listener mechanism provided by JSF2.0 implementation. Basically in the JSF page I assigned an id to the HtmlSelectItems component (living inside a h:column) and set it with a pre render f:event element.
The f:event is pointing to one of my methods which receives the component id and process it.
My issue is that the HtmlSelectItems instance is SHARED between all the table rows, and if say I call HtmlSelectItems.setRender(false) on one dropdown list component, all the subsequent rows will stop displaying the drop downs. In fact the f:event pre render listener will stop getting called once the first setRender(false) is called on a dropdown
I can understand the fact that sharing one HtmlSelectItems instance between the table rows
has a positive impact on performance overall, but shouldn’t this component instance be re-initialized on each row?
Thanks a lot for any clarifications in this regard.
You need to let the
renderedcondition depend on the row itself, not on the parent bean.E.g.
instead of
Or if it needs to be determined by the
#{bean}rather than#{item}due to some design restrictions, then there are several ways.If you’re using
DataModelas datatable’svalue, then you can get the current row as follows:If not, then maintain a
Map<Long, Boolean>instead where the key is actually the identifier of the row item and the value represents whether the dropdown should be shown. This can then be used as follows: