Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

datatable problem

 
Smitha H Rao
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • 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>
<hutputText value="quarterlySales.apples"/>
</h:column>


<h:column>
<f:verbatim>$</f:verbatim>
<hutputText 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?
 
Ghaith Rabadi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the problem in <hutputText value="quarterlySales.apples"/>
it must be <hutputText value="#{quarterlySales.apples}"/>
 
Smitha H Rao
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have corrected that line. But still I face same problem.. . can anyone please help me..
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic