Pregunta

I have a problem with h:datatable and ui:repeat.

I have the next objects structure:

  • Product
    • SubproductType1
    • SubproductType2
    • SubproductType3

In the datatable I need to show info of the Product and info of one of the subproducts like:

Name         Price       StartDate       EndDate
P1Name        25$        01/01/13        01/07/13
P2Name        25$        01/01/13        01/07/13

The price and Dates comes from the SubproductType2 price attribute.

So if I have this

<h:dataTable value="#{bundleBean.products}" var="myBundle" >

    <ui:param name="currentSubProd" value="#sbaBean.getSubProdOfBundleFilterByCategory(myBundle.id, categoryType.internet)}" />
                    <h:column>
                    <f:facet name="header" >Name</f:facet>
                            #{myBundle.name}
                </h:column>
                    <h:column>
                    <f:facet name="header" >Price</f:facet>
                            #{currentSubProd.price}
                </h:column>
                    <h:column>
                    <f:facet name="header" >StartDate</f:facet>
                            #{currentSubProd.startDate}
                </h:column>
                    <h:column>
                    <f:facet name="header" >EndDate</f:facet>
                            #{currentSubProd.endDate}
                </h:column>
</h:dataTable>                      

It works perfectly but it invokes to the bean method every time #currentSubProd is called in the xhtml file, 3 times in this case. So if I have some query inside the method the DB is doing the query 3 times.

I realiced that with ui:repeat inside a column it works fine but you can't put and ui:repeat outside it using an ui:repeat for every column on the datatable.

Like this (NOT Working):

    <ui:repeat name="currentSubProd" value="#sbaBean.getSubProdOfBundleFilterByCategory(myBundle.id, categoryType.internet)}" >
                    <h:column>
                    <f:facet name="header" >Name</f:facet>
                            #{myBundle.name}
                </h:column>
                    <h:column>
                    <f:facet name="header" >Price</f:facet>
                            #{currentSubProd.price}
                </h:column>
                    <h:column>
                    <f:facet name="header" >StartDate</f:facet>
                            #{currentSubProd.startDate}
                </h:column>
                    <h:column>
                    <f:facet name="header" >EndDate</f:facet>
                            #{currentSubProd.endDate}
                </h:column>
    </ui:repeat>
</h:dataTable>

Any idea how to solve that?

Thanks in advance.

Regards.

¿Fue útil?

Solución

Just stop doing business logic in getter methods. Getter methods should only return already-prepared data.

Do the business logic in (post)constructor or action(listener) methods instead.

See also:

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top