Reputation: 12214
Is it possible to use the same datatable with multiple data sources? If yes, then how? Can someone give me an example of it? To be more precise, can we bind/unbind different sources to datatable programaticaly?
Upvotes: 1
Views: 844
Reputation: 2590
Some sample code is given below for clarity ...
<p:selectOneRadio id="myRadio" value="#{beanProductDetails.selectedtype}">
<f:selectItems value="#{bean.types}"/>
<f:ajax event="valueChange" update="panel_CATALOG" listener="#{bean.typeChanged}" />
</p:selectOneRadio>
<h:panelGrid id="panel_CATALOG">
<p:dataTable id="table_Details" value="#{bean.list_Details}">
........
</p:dataTable>
</h:panelGrid>
Provide selectOneRadio to decide which data source to use. Here, in typeChanged method of the bean, decide what should be list_Details depending on the selectedtype.
Upvotes: 1
Reputation: 320
You can use Composite Component, for more info follow this tutorial
http://courses.coreservlets.com/Course-Materials/pdf/jsf/jsf2/JSF2-Composite-Components.pdf
and sample file exist in this path
http://www.coreservlets.com/JSF-Tutorial/jsf2/code/composite-components.zip
Upvotes: 1
Reputation: 30025
Yes this is possible. Normally you set the value attribute of your datatable to a List<MyClass>
where MyClass
can be a pojo or an entity. The list is an instance variable of your backing bean and of course the variable can change at runtime.
Upvotes: 2