- This topic has 4 replies, 5 voices, and was last updated 19 years, 3 months ago by
shomprabu.
-
AuthorPosts
-
axinixeMemberhi all,
im trying to make a web page where i get data from a datamodel and put it in a datadable,
but somehow it aint working. Can u help me?datatable code:
<h:dataTable rows="2" value="#{ProductBean.lijstProducten}" binding="#{ProductBean.lijstProducten}" rendered="true" var="product" id="producten"> <h:column> <h:outputText value="Title"/> <h:outputText value="#{product.naam}"/> </h:column> <h:column> <h:outputText value="Prijs"/> <h:outputText value="#{product.prijs}"/> </h:column> </h:dataTable>
ProductBean code:
public final class ProductBean extends Object { DataModel lijstProducten = new ListDataModel(); DataModel lijstPrijzen = new ListDataModel(); product productje; public ProductBean() { super(); productje = new product("haha","100"); lijstProducten.setWrappedData(productje); } public DataModel getLijstProducten() { return lijstProducten; } public void setLijstProducten(Object data) { lijstProducten.setWrappedData(data); } }
Product code:
public class product { private String naam; private String prijs; public product(String n,String p) { naam=n; prijs=p; } public String getPrijs() { return prijs; } public String getNaam() { return naam; } public void setPrijs(String p) { prijs = p; } public void setNaam(String n) { naam=n; } }
thanks in advance,
grtz
Riyad KallaMemberMoving to OT > Soft Dev
arjan.tijmsMember[offtopic]
@axinixe: Although the structure of your code is still clear, maybe you’d beter not use Dutch variable names, especially not when asking for help on an international forum.
[/offtopic]
HewittchMemberHi, here are a few remarks:
– Of course your ListDataModel is a Collection?
– Why force rows=”2″ in the datatable declaration? It is supposed to be dynamic and depend on your collection’s size
– Is binding=”#{ProductBean.lijstProducten}” really necessary? I have 2 datatables who behave fine without it.Best regards.
ERO
shomprabuMemberpublic ProductBean() {
super();
productje = new product(“haha”,”100″);
List productjes = new ArrayList();
productjes.add(productje);
lijstProducten.setWrappedData(productjes);
}-Should work, if u have many products just keep adding to the List producjes. But the jsf u have written will repeat the title [Table Header]. To avoid that use facet header.
<h:dataTable value=”#{ProductBean.lijstProducten}” var=”product” id=”producten”>
<h:column>
<f:facet name=”header”>
<h:outputText value=”Title”/>
</f:facet>
<h:outputText value=”#{product.naam}”/>
</h:column>
<h:column>
<f:facet name=”header”>
<h:outputText value=”Prijs”/>
</f:facet>
<h:outputText value=”#{product.prijs}”/>
</h:column>
</h:dataTable>Secondly the way u did binding was incorrect. U can bind only to UIComponents, for dataTable bind it to UIData. So u Bean class should have
UIData productUIData = null;
have setter and getter Method for it.
Binding is required only when u require in Bean the instance of DataTable Components. Since the dataTable, the content which u render is static text, binding is not necessary-Shom
-
AuthorPosts