You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Manfred Geiler <ma...@apache.org> on 2004/11/22 16:54:23 UTC
Re: populate resultSet
Francesco,
Just place your "populate()" call into your getList method, use the
<x:dataTable> instead of <h:dataTable>, set the "preserveData" attribute
to true and lean back. ;-)
There is some (not yet neatly documented) magic inside the extended data
table that makes the component do call your getList method only once per
request.
HTH,
Manfred
Francesco Consumi wrote:
> Hi people,
>
> I've some doubt about the best way of populating a result set:
>
> <h:dataTable value="#{bean.List}"...../>
>
> I've a dataTable linked to an ArrayList. I populate the array list with
> result
> of a query.
> what do you think is the best place to place call to "populate()" method ?
> if I put that call in "getList" method of bean, the populate() is being
> called a
> lot of times. If I call it once in bean() main procedure, the result is
> not kept
> up to date.
>
> thanks,
>
>
> --
> Francesco Consumi
> Ufficio Sistemi informativi
> Istituto degli Innocenti
> Piazza SS.Annunziata, 12
> 50122 Firenze
> consumi at istitutodeglinnocenti.it
> Tel. +39 055 2037320
> ICQ# 12516133
>
>
>
Re: populate resultSet
Posted by Francesco Consumi <co...@istitutodeglinnocenti.it>.
Scrive Manfred Geiler <ma...@apache.org>:
....snip.....
many thanks for explainations. Now it is clear.
For the moment I've solved problem calling the "populate()" method inside the
action param of Save button.
But I keep searching a more general solution. I've a lot of dataTables without
filters, but that have to be filled just before showing......
--
Francesco Consumi
Ufficio Sistemi informativi
Istituto degli Innocenti
Piazza SS.Annunziata, 12
50122 Firenze
consumi at istitutodeglinnocenti.it
Tel. +39 055 2037320
ICQ# 12516133
Re: populate resultSet
Posted by Manfred Geiler <ma...@apache.org>.
There is a problem with rendered="#{bean.list.count > 0}" (or better
rendered="#{not empty bean.list}") for a dataTable in principle:
Imagine the following scenario:
- We have a list page with some kind of filter criterias in a form
- The first time the page is rendered with an empty list
- After a submit the page is rendered again. Per definition the rendered
attribute is calculated early during the first lifecycle phase. Should
we refresh the list before the restore state or apply request values phase?
--> if yes, we would refresh the list from the DB with wrong query
criterias, because the filter inputs have not yet been propagated to the
model beans (this happens in updateModel phase).
--> if no, we use the old list (which is still empty) and the rendered
attribute evaluates to false. That means our list component does not
participate in lifecycle processing at all. So, the new filter criterias
would perhaps give a non-empty list, but the list would not be rendered.
A stand-off situation!
Conclusion: In a situation where inputs on the page influence the size
of the list (i.e. filter form inputs), never use the rendered attibute
in a dataTable to determine if the list is empty or not empty.
HTH,
Manfred
Francesco Consumi wrote:
> Scrive Manfred Geiler <ma...@apache.org>:
>
>> This is the culprit: rendered="#{mb.rsTelxSett.count > 0}"
>> Please use the renderedIfEmpty attribute instead:
>>
> I've just tried, and for some aspects it works: the getList method is being
> called "only" times... :-)
>
> the better place, I think, should be an hypothetical "OnPageLoad"
> action.......
>
>
>
>
>
> --
> Francesco Consumi
> Ufficio Sistemi informativi
> Istituto degli Innocenti
> Piazza SS.Annunziata, 12
> 50122 Firenze
> consumi at istitutodeglinnocenti.it
> Tel. +39 055 2037320
> ICQ# 12516133
>
>
>
Re: populate resultSet
Posted by Francesco Consumi <co...@istitutodeglinnocenti.it>.
Scrive Manfred Geiler <ma...@apache.org>:
> This is the culprit: rendered="#{mb.rsTelxSett.count > 0}"
> Please use the renderedIfEmpty attribute instead:
>
I've just tried, and for some aspects it works: the getList method is being
called "only" times... :-)
the better place, I think, should be an hypothetical "OnPageLoad"
action.......
--
Francesco Consumi
Ufficio Sistemi informativi
Istituto degli Innocenti
Piazza SS.Annunziata, 12
50122 Firenze
consumi at istitutodeglinnocenti.it
Tel. +39 055 2037320
ICQ# 12516133
Re: populate resultSet
Posted by Manfred Geiler <ma...@apache.org>.
This is the culprit: rendered="#{mb.rsTelxSett.count > 0}"
Please use the renderedIfEmpty attribute instead:
Excerpt from the TLD:
8X-------------------------------------------------------
<attribute>
<name>renderedIfEmpty</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
<description>
Indicates whether this table should be rendered if the
underlying DataModel is
empty.
You could as well use rendered="#{not empty
bean.list}", but this one causes
the getList method of your model bean beeing called up
to five times per
request, which is not optimal when the list is backed
by a DB table.
Using renderedIfEmpty="false" solves this problem,
because the MyFaces
extended HtmlDataTable automatically caches the
DataModel and calles the
model getter only once per request.
Default: true
</description>
</attribute>
8X-------------------------------------------------------
HTH,
Manfred
Francesco Consumi wrote:
> Scrive Manfred Geiler <ma...@apache.org>:
>
>> Francesco,
>> Just place your "populate()" call into your getList method, use the
>> <x:dataTable> instead of <h:dataTable>, set the "preserveData" attribute
>> to true and lean back. ;-)
>> There is some (not yet neatly documented) magic inside the extended data
>> table that makes the component do call your getList method only once per
>> request.
>
>
> Thanks, but I'm sorry to inform you that even if I use x:dataTable, the
> "getList" method is being called at least 8 (eight) times....
>
> here is the dataTable code:
> "result" is the ArrayList populated. I've to populate it at every page
> request
> because its query depends on some parameters that the user can select in
> form
> in order to filter result set.
>
>
> <x:dataTable var="g" value="#{mb.rsTelxSett.result}"
> styleClass="standardTable"
> headerClass="standardTable_SortHeader"
> footerClass="standardTable_Footer"
>
> columnClasses="standardTable_Column,standardTable_Column,standardTable_Column,standardTable_ColumnRight,standardTable_ColumnRight"
>
> rendered="#{mb.rsTelxSett.count > 0}"
> preserveDataModel="true">
> <f:facet name="header">
> <h:panelGroup>
> <h:outputText value="Statistiche telefono"/>
> </h:panelGroup>
> </f:facet>
> <h:column id="c0">
> <f:facet name="header"><h:outputText value="Utente"
> id="h0"/></f:facet>
> <h:outputText value="#{g.COGNOMENOME}" id="c1Text0"/>
> </h:column>
> <h:column id="c1">
> <f:facet name="header"><h:outputText value="Codice"
> id="h1"/></f:facet>
> <h:outputText value="#{g.CODICE}" id="c1Text"/>
> </h:column>
> <h:column id="c2">
> <f:facet name="header"><h:outputText value="Centro di Costo"
> id="h2"/></f:facet>
> <h:outputText value="#{g.NOME}" id="c1Text2"/>
> </h:column>
> <h:column id="c3">
> <f:facet name="header"><h:outputText value="Scatti"
> id="h3"/></f:facet>
> <h:outputText value="#{g.TOT}" id="c1Text3"/>
> </h:column>
> <h:column id="c4">
> <f:facet name="header"><h:outputText value="Costo totale"
> id="h4"/></f:facet>
> <h:outputText value="#{g.COSTOTOT}" id="c1Text4">
> <f:convertNumber type="currency"/>
> </h:outputText>
> </h:column>
> </x:dataTable>
>
>
>
> many thanks for support.
>
> --
> Francesco Consumi
> Ufficio Sistemi informativi
> Istituto degli Innocenti
> Piazza SS.Annunziata, 12
> 50122 Firenze
> consumi at istitutodeglinnocenti.it
> Tel. +39 055 2037320
> ICQ# 12516133
>
>
>
Re: populate resultSet
Posted by Francesco Consumi <co...@istitutodeglinnocenti.it>.
Scrive Manfred Geiler <ma...@apache.org>:
> Francesco,
> Just place your "populate()" call into your getList method, use the
> <x:dataTable> instead of <h:dataTable>, set the "preserveData" attribute
> to true and lean back. ;-)
> There is some (not yet neatly documented) magic inside the extended data
> table that makes the component do call your getList method only once per
> request.
Thanks, but I'm sorry to inform you that even if I use x:dataTable, the
"getList" method is being called at least 8 (eight) times....
here is the dataTable code:
"result" is the ArrayList populated. I've to populate it at every page request
because its query depends on some parameters that the user can select in form
in order to filter result set.
<x:dataTable var="g" value="#{mb.rsTelxSett.result}"
styleClass="standardTable"
headerClass="standardTable_SortHeader"
footerClass="standardTable_Footer"
columnClasses="standardTable_Column,standardTable_Column,standardTable_Column,standardTable_ColumnRight,standardTable_ColumnRight"
rendered="#{mb.rsTelxSett.count > 0}"
preserveDataModel="true">
<f:facet name="header">
<h:panelGroup>
<h:outputText value="Statistiche telefono"/>
</h:panelGroup>
</f:facet>
<h:column id="c0">
<f:facet name="header"><h:outputText value="Utente"
id="h0"/></f:facet>
<h:outputText value="#{g.COGNOMENOME}" id="c1Text0"/>
</h:column>
<h:column id="c1">
<f:facet name="header"><h:outputText value="Codice"
id="h1"/></f:facet>
<h:outputText value="#{g.CODICE}" id="c1Text"/>
</h:column>
<h:column id="c2">
<f:facet name="header"><h:outputText value="Centro di Costo"
id="h2"/></f:facet>
<h:outputText value="#{g.NOME}" id="c1Text2"/>
</h:column>
<h:column id="c3">
<f:facet name="header"><h:outputText value="Scatti"
id="h3"/></f:facet>
<h:outputText value="#{g.TOT}" id="c1Text3"/>
</h:column>
<h:column id="c4">
<f:facet name="header"><h:outputText value="Costo totale"
id="h4"/></f:facet>
<h:outputText value="#{g.COSTOTOT}" id="c1Text4">
<f:convertNumber type="currency"/>
</h:outputText>
</h:column>
</x:dataTable>
many thanks for support.
--
Francesco Consumi
Ufficio Sistemi informativi
Istituto degli Innocenti
Piazza SS.Annunziata, 12
50122 Firenze
consumi at istitutodeglinnocenti.it
Tel. +39 055 2037320
ICQ# 12516133