facebook

JSF datatable

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #244098 Reply

    axinixe
    Member

    hi 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

    #244136 Reply

    Riyad Kalla
    Member

    Moving to OT > Soft Dev

    #244233 Reply

    arjan.tijms
    Member

    [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]

    #246517 Reply

    Hewittch
    Member

    Hi, 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

    #246601 Reply

    shomprabu
    Member

    public 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

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: JSF datatable

You must be logged in to post in the forum log in