• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

datatable problem

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to display data using datatables. I have tried the examples given in coreservlets but its not working for me. The table data is not populating. The page is not even calling the getter method.
The jsp file:
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<f:view>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD><TITLE>Fruit Sales</TITLE>
<LINK REL="STYLESHEET"
HREF="./css/styles.css"
TYPE="text/css">
</HEAD>
<BODY>
<CENTER>
<TABLE BORDER=5>
<TR><TH CLASS="TITLE">Fruit Sales By Quarter</TH></TR>
</TABLE>
<H2>Apples and Oranges</H2>

<h:dataTable value="#{salesBean.yearlySales}" var="quarterlySales" border="1">
<h:column>
<f:verbatim>$</f:verbatim>
<h:outputText value="quarterlySales.apples"/>
</h:column>


<h:column>
<f:verbatim>$</f:verbatim>
<h:outputText value="#{quarterlySales.oranges}"/>
</h:column>

</h:dataTable>

</CENTER>
</BODY></HTML>


</f:view>

The bean: SalesBean
package coreservlets;

import java.util.ArrayList;

public class SalesBean {
private double apples = 0.0, oranges = 0.0;
private ArrayList yearlySales;

public SalesBean() {
public SalesBean(double apples, double oranges) {
setApples(apples);
setOranges(oranges);
}

public double getApples() { return(apples); }

public void setApples(double apples) {
this.apples = apples;
}

public double getOranges() { return(oranges); }

public void setOranges(double oranges) {
this.oranges = oranges;
}

public ArrayList getYearlySales() {
yearlySales = new ArrayList();
yearlySales.add(new SalesBean(100.22, 200.32));
yearlySales.add(new SalesBean(300.44, 400.55));
yearlySales.add(new SalesBean(500.66, 600.77));
yearlySales.add(new SalesBean(700.88, 800.99));
return(yearlySales);
}

}


my faces-config entry is: <managed-bean>
<managed-bean-name>salesBean</managed-bean-name>
<managed-bean-class>
coreservlets.SalesBean
</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

can anyone please tell me where I am going wrong?
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the problem in <h:outputText value="quarterlySales.apples"/>
it must be <h:outputText value="#{quarterlySales.apples}"/>
 
Smitha H Rao
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have corrected that line. But still I face same problem.. . can anyone please help me..
 
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


public SalesBean() {
public SalesBean(double apples, double oranges) {
setApples(apples);
setOranges(oranges);
}


looks like you are missing a closing parenthesis for the no-args constructor.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic