myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <simon.kitch...@rhe.co.nz>
Subject Re: Dynamic panelGrid within dataTable
Date Tue, 13 Feb 2007 02:03:38 GMT
fastbob wrote:
> Howdy,
> I'm trying to dynamically generate a panelGrid from within a dataTable (yes,
> dynamic generation is required). The panelGrid will be displayed as details
> when the user clicks on a row in the table, and each row in the table will
> generate different contents for its panelGrid. This technique seems to fail
> when the panelGrid is bound to the var of the dataTable, but not, for
> instance, when accessing a panelGrid property of some other request or
> session bean. The exception (below) seems to indicate that the dataTable var
> is null when the panelGrid binding is evaluated.
> 
> Here's an extract of the tags:
> 
>             <h:form id="createReports">
>             <t:dataTable id="reports" var="report"
>                             value="#{ReportDefinitions.reportList}"
>                              sortable="true"
>                             preserveDataModel="false" [...]>
> 
>                   <t:column sortPropertyName="name">
>                      <f:facet name="header">
>                         <h:outputText value="REPORT NAME"/>
>                      </f:facet>
>                      <h:outputText value="#{report.name}"/>
>                   </t:column>
> 
>                   <f:facet name="detailStamp">
>                      <t:panelGrid >
> 
>       --->                   <t:panelGrid binding="#{report.formPanelGrid}"
> />
> 
>                      </t:panelGrid>
>                   </f:facet>
>                </t:dataTable>
>             </h:form>
> 

Sorry, but you just cannot use the "var" of a datatable in a binding 
expression. Cannot be done.

A table uses the "flyweight" pattern to reduce the amount of memory 
needed for its child components. Suppose a table has 5 t:column children 
each containing one facet child component and one normal child 
component. These 15 components (f:facet is not a component) are then 
reused for each row; regardless of whether the table has 1 row or 500 
rows, the number of child components is still 15.

The "var" variable only exists while a table is processing its children 
on postback or render, and does not exist at any other time.

A binding-expression always passes a UIComponent object to the target 
property, so clearly it is not specific to any row. Actually, bindings 
are evaluated during the "restore view" phase, at which point the "var" 
variable does not exist.

You'll need to take a different approach to whatever problem it is that 
you are trying to solve using this binding.

Binding should generally be regarded as a last resort anyway; it is 
sometimes necessary but better avoided if possible as it results in 
tighter coupling between the presentation and backing bean.

Regards,

Simon

Mime
View raw message