Problem with <p:dataTable>

UI Components for JSF
johnwp
Posts: 10
Joined: 13 Jul 2010, 18:52

13 Jul 2010, 19:57

Hello :)

I am very new to JSF and PrimeFaces, so please forgive me if I sound naive. I just installed PrimeFaces 1.0.2 for JSF 1.2, read through the Getting Started Guide, and was able to test my PrimeFaces installation by successfully rendering <p:editor />. Unfortunately, I am having a problem with the basic usage of a standard dataTable.

I tried refactoring my code to fit the example on page 102 of the PrimeFaces User's Guide and also the basic dataTable example at the PrimeFaces Component Showcase. Unfortunately, I am getting the following 500 error from GlassFish 3.0.1:
javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'date_completed'.
Please note that I have tried replacing <h:outputText value="#{job.date_completed} " /> with <h:outputText value="#{job.fitness} " /> and received the error:
javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'fitness'.
My code is as followed. Thanks in advance for your help.

simulations.jsp

Code: Select all

...
<p:dataTable var="job" value="#{simMan.inst} " >
	<p:column>
		<f:facet name="header">
			Date Completed
		</f:facet>
		<h:outputText value="#{job.date_completed} " />
	</p:column>

	<p:column>
		<f:facet name="header">
			Problem Instance ID
		</f:facet>
		<h:outputText value="#{job.probinstid} " />
	</p:column>

	<p:column>
		<f:facet name="header">
			Exceedances
		</f:facet>
		<h:outputText value="#{job.exceedances} " />
	</p:column>

	<p:column>
		<f:facet name="header">
			Fitness
		</f:facet>
		<h:outputText value="#{job.fitness} " />
	</p:column>
</p:dataTable>
...
SimulationManager.java

Code: Select all

...

public class SimulationManager implements Serializable {

	...

	public SimulationManager() throws SQLException {
		df = new DateFormatter();
		try {
			populateInst(source);
		} catch(Exception e) { }
	}

		private List<Instance> inst;

		public List<Instance> getInst() {
			return inst;
		}

		public void populateInst(DataSource src) throws SQLException {

			Connection db = null;
		    	db = src.getConnection();

			String sql = "SELECT * FROM probinst WHERE problemid = " + problemid + " " +
				     "ORDER BY " + getInstSortby() + " " + getInstDirection();
			ResultSet rs = db.createStatement().executeQuery(sql);

			rs.last();
			int numberOfRows = rs.getRow();
			rs.beforeFirst();

			inst = new ArrayList<Instance>();

			while(rs.next())
				inst.add(new Instance(rs.getRow(),
						      rs.getInt("probinstid"),
						      rs.getDate("date_completed").toString(),
						      rs.getTime("time_completed").toString(),
						      rs.getDouble("fitness"),
						      rs.getInt("exceedances"),
						      rs.getDouble("concmean"),
						      rs.getDouble("concstd"),
						      rs.getDouble("concmax"),
						      rs.getDouble("concmin"),
						      false));

			rs.close();
			db.close();
		}
	...
}
Instance.java

Code: Select all

package com.optimization;

public class Instance {
	private Integer probinstid;
	private String date_completed;
	private String time_completed;
	private Double fitness;
	private Integer exceedances;
	private Double concmean;
	private Double concstd;
	private Double concmax;
	private Double concmin;
	private boolean selected;
	private Integer row;

	public Instance() {
	}

	public Instance(Integer row, Integer probinstid, String date_completed, String time_completed, Double fitness, Integer exceedances, Double concmean, Double concstd, Double concmax, Double concmin, boolean selected) {

		this.row = row;
		this.probinstid = probinstid;
		this.date_completed = date_completed;
		this.time_completed = time_completed;
		this.fitness = fitness;
		this.exceedances = exceedances;
		this.concmean = concmean;
		this.concstd = concstd;
		this.concmax = concmax;
		this.concmin = concmin;
		this.selected = selected;
	}

	public int getRow() {
		return row;
	}

	public void setRow(Integer row) {
		this.row = row;
	}

	public boolean isSelected() {
		return selected;
	}

	public void setSelected(boolean selected) {
		this.selected = selected;
	}

	public Double getConcmax() {
		return concmax;
	}

	public void setConcmax(Double concmax) {
		this.concmax = concmax;
	}

	public Double getConcmean() {
		return concmean;
	}

	public void setConcmean(Double concmean) {
		this.concmean = concmean;
	}

	public Double getConcmin() {
		return concmin;
	}

	public void setConcmin(Double concmin) {
		this.concmin = concmin;
	}

	public Double getConcstd() {
		return concstd;
	}

	public void setConcstd(Double concstd) {
		this.concstd = concstd;
	}

	public String getdate_completed() {
		return date_completed;
	}

	public void setdate_completed(String date_completed) {
		this.date_completed = date_completed;
	}

	public Integer getexceedances() {
		return exceedances;
	}

	public void setexceedances(Integer exceedances) {
		this.exceedances = exceedances;
	}

	public Double getFitness() {
		return fitness;
	}

	public void setFitness(Double fitness) {
		this.fitness = fitness;
	}

	public Integer getProbinstid() {
		return probinstid;
	}

	public void setProbinstid(Integer probinstid) {
		this.probinstid = probinstid;
	}

	public String gettime_completed() {
		return time_completed;
	}

	public void settime_completed(String time_completed) {
		this.time_completed = time_completed;
	}
}

callahan
Posts: 768
Joined: 27 May 2010, 22:52

14 Jul 2010, 07:10

Hi,

Is class SimulationManager registered as a managed bean in faces-config.xml?

The following:

Code: Select all

   public String getdate_completed() {
      return date_completed;
   }

   public void setdate_completed(String date_completed) {
      this.date_completed = date_completed;
   }
Should be:

Code: Select all

public String getDate_completed() {
      return date_completed;
   }

   public void setDate_completed(String date_completed) {
      this.date_completed = date_completed;
   }

Bexx
Posts: 18
Joined: 10 May 2010, 15:48
Location: Saarbrücken

14 Jul 2010, 11:03

it seems to me, that the value you are handing over to the dataTable

Code: Select all

value="#{simMan.inst}
is not of the type list.
(dataTable expects some type of a list for the value-attribute)

Even if you want to display just one value, you need to do this in a list.
If you try using a String instead, your error message is completly understandable,
cause since when does the class "String" have a property 'date_completed'. :)
Thanks in advance :)

__________________
Achieving results often isn't a matter of will
it's a matter of strength...
__________________
JSF 2.0/ Glassfish v3
NetBeans 6.9

User avatar
michiel
Posts: 240
Joined: 07 Jun 2010, 09:12
Location: Belgium

14 Jul 2010, 11:28

for fitness:

Code: Select all

<h:outputText value="#{job.fitness} " >
    <f:converter converterId="javax.faces.Double"/>
</h:outputText>
JSF-2.0, mojarra-2.0.2-FCS and PrimeFaces-2.1 on GlassFish v3.0.1 (build 22)

Bexx
Posts: 18
Joined: 10 May 2010, 15:48
Location: Saarbrücken

14 Jul 2010, 11:37

how is that related to the problem?
Thanks in advance :)

__________________
Achieving results often isn't a matter of will
it's a matter of strength...
__________________
JSF 2.0/ Glassfish v3
NetBeans 6.9

johnwp
Posts: 10
Joined: 13 Jul 2010, 18:52

14 Jul 2010, 20:48

Thanks for all of your replies. I really appreciate it. However, the problem still persists.

bmacmanus, thank you very much for you ideas.
NetBeans for some reason automatically generated those getters and settings incorrectly. Thanks for pointing it out. I have corrected the capitalization errors, but unfortunately does not change my error. SimulationManager is registered in faces-config.xml as followed. Is this configuration correct?

Code: Select all

  <managed-bean>
    <managed-bean-name>simMan</managed-bean-name>
    <managed-bean-class>com.optimization.SimulationManager</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
      <property-name>userMan</property-name>
      <value>#{userMan}</value>
    </managed-property>
  </managed-bean>
Bexx, thank you very much for your reply,
I believe I'm now handing the dataTable a List. My original SimulationManager.java code posted above indicates that I was passing it an ArrayList (which works with the standard JSF h:dataTable component), but have since changed it to a List, and unfortunately does not change my error.

michiel,
I have tried using f:converter on all of the outputText components in my dataTable but still receive the same error message. For example, using:

Code: Select all

<p:dataTable var="job" value="#{simMan.inst} " >
	<p:column>
		<f:facet name="header">
			Fitness
		</f:facet>
		<h:outputText value="#{job.fitness} " >
			<f:converter converterId="javax.faces.Double"/>
		</h:outputText>
	</p:column>
</p:dataTable>
Produces the error:
javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'fitness'.
and using

Code: Select all

<p:dataTable var="job" value="#{simMan.inst} " >
	<p:column>
		<f:facet name="header">
			Problem Instance ID
		</f:facet>
		<h:outputText value="#{job.probinstid} " />
	</p:column>
</p:dataTable>
Produces the error:
javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'probinstid'.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

15 Jul 2010, 16:58

johnwp, to give a try, can you remove those whitespaces at the end of your EL expressions?

Code: Select all

value="#{simMan.inst}" 
instead of

Code: Select all

value="#{simMan.inst} "

johnwp
Posts: 10
Joined: 13 Jul 2010, 18:52

16 Jul 2010, 23:42

Thanks so much optimus.prime. Such a simple mistake! I think I might have gotten that code from the component showcase.

Making those changes got rid of the error I was receiving, except now my problem is that the dataTable doesn't show any data in it for some reason. Just blank. No header or anything. So strange. Do you have any idea why this might be?

In addition to passing p:dataTable a List, I have also tried passing it an array of Instances to no avail.

Is my simulation.jsp file configured correctly?

Code: Select all

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
  <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
  <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
  <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
  <%@ taglib uri="http://corejsf.com/upload" prefix="corejsf" %>
  <%@ taglib uri="http://primefaces.prime.com.tr/ui" prefix="p" %>
  
  <f:view>
    <head>
      <title><h:outputText value="#{msg.title}" /></title>
	  <p:resources />
      <script type="text/javascript" src="javascript/script.js"></script>
    </head>
...
Thanks again :)

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

17 Jul 2010, 17:47

Do you receive any error? Does h:dataTable display your data?

johnwp
Posts: 10
Joined: 13 Jul 2010, 18:52

17 Jul 2010, 18:05

Oh, thank you optimus.prime. I took a good look at my table and removed things that apparently were preventing it from working.

I changed my columns from this...

Code: Select all

<p:column>
	<f:facet name="header">
		<h:outputLink value="?page=search&userid=#{param.userid}&status=#{param.status}&startDate=#{param.startDate}&endDate=#{param.endDate}&sortby=user&direction=#{param.direction == 'desc' ? 'asc' : 'desc'}">
			User
		</h:outputLink>
	</f:facet>
	<h:panelGrid onclick="location='?page=problemset&problemid=#{jb.problemid}'">
		<h:outputText value="#{jb.user}" />
	</h:panelGrid>
</p:column>
To this...

Code: Select all

<p:column>
	<f:facet name="header">
		<h:outputText value="User" />
	</f:facet>
	<h:outputText value="#{jb.user}" />	
</p:column>
My bad :roll: And it works perfectly! Love it! Thanks again for you help.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 55 guests