Hi everyone,
I am new to JSF and primefacs.
I am trying to implement a datatable similar to the primefaces showcase example here.. http://www.primefaces.org/showcase/ui/d ... Column.jsf
I need a working version that works similar to the one above and also has a delete and update functionality.
Any help will be greatly appreciated. The link example above does not work.complains about (import org.primefaces.examples.domain.Car;) is not found and and once I get just Car class I get "no records found"
I have eclipse , tomcat 6, primefaces 3.0.M3/2.2.1
The example code above with Car class is...
datatable.xhtlm
----------------
<html xmlns="http://www.w3c.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
<link type="text/css" rel="stylesheet" href="themes/bluesky/skin.css" />
</h:head>
<h:body>
<h:form prependId="false">
<p:dataTable var="car" value="#{tableBean.cars}" paginator="true" rows="10">
<p:column>
<f:facet name="header">
<h:outputText value="Model" />
</f:facet>
<h:outputText value="#{car.model}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Year" />
</f:facet>
<h:outputText value="#{car.year}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Manufacturer" />
</f:facet>
<h:outputText value="#{car.manufacturer}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Color" />
</f:facet>
<h:outputText value="#{car.color}" />
</p:column>
<p:column style="width:32px">
<p:commandButton update="display" oncomplete="carDialog.show()"
image="ui-icon ui-icon-search">
<f:setPropertyActionListener value="#{car}"
target="#{tableBean.selectedCar}" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:dialog header="Car Detail" widgetVar="carDialog" resizable="false"
width="200" showEffect="explode" hideEffect="explode">
<h:panelGrid id="display" columns="2" cellpadding="4">
<f:facet name="header">
<h:commandButton value="View" />
</f:facet>
<h:outputText value="Model:" />
<h:outputText value="#{tableBean.selectedCar.model}" />
<h:outputText value="Year:" />
<h:outputText value="#{tableBean.selectedCar.year}" />
<h:outputText value="Manufacturer:" />
<h:outputText value="#{tableBean.selectedCar.manufacturer}" />
<h:outputText value="Color:" />
<h:outputText value="#{tableBean.selectedCar.color}" />
</h:panelGrid>
</p:dialog>
</h:form>
</h:body>
</html>
================================================
TableBeans.java
--------------------
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
public class TableBean {
private final static String[] colors;
private final static String[] manufacturers;
static {
colors = new String[10];
colors[0] = "Black";
colors[1] = "White";
colors[2] = "Green";
colors[3] = "Red";
colors[4] = "Blue";
colors[5] = "Orange";
colors[6] = "Silver";
colors[7] = "Yellow";
colors[8] = "Brown";
colors[9] = "Maroon";
manufacturers = new String[10];
manufacturers[0] = "Mercedes";
manufacturers[1] = "BMW";
manufacturers[2] = "Volvo";
manufacturers[3] = "Audi";
manufacturers[4] = "Renault";
manufacturers[5] = "Opel";
manufacturers[6] = "Volkswagen";
manufacturers[7] = "Chrysler";
manufacturers[8] = "Ferrari";
manufacturers[9] = "Ford";
}
private List<Car> cars;
private Car selectedCar;
public TableBean() {
cars = new ArrayList<Car>();
populateRandomCars(cars, 50);
}
private void populateRandomCars(List<Car> list, int size) {
for(int i = 0 ; i < size ; i++)
list.add(new Car(getRandomModel(), getRandomYear(), getRandomManufacturer(), getRandomColor()));
}
public Car getSelectedCar() {
return selectedCar;
}
public void setSelectedCar(Car selectedCar) {
this.selectedCar = selectedCar;
}
public List<Car> getCars() {
return cars;
}
private int getRandomYear() {
return (int) (Math.random() * 50 + 1960);
}
private String getRandomColor() {
return colors[(int) (Math.random() * 10)];
}
private String getRandomManufacturer() {
return manufacturers[(int) (Math.random() * 10)];
}
private String getRandomModel() {
return UUID.randomUUID().toString().substring(0, 8);
}
}
=========================================================================
Car.java
-------------
import java.util.Date;
public class Car {
private String model;
private int year;
private String manufacturer;
private String color;
public Car(String model, int year, String manufacturer, String color) {
this.model = model;
this.year = year;
this.manufacturer = manufacturer;
this.color = color;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
}
Thanks
pfrules
Datatable problem
I got part of my issue resolved. I totally forgot the following in TableBean.java
@ManagedBean
@SessionScoped
That got the first example to work.
Now I have weird problem,
If you try veiw a record and you click the image on the right, it pulls up the wrong record.
Any idea as to why??
Thanks in advance.
pfrules
@ManagedBean
@SessionScoped
That got the first example to work.
Now I have weird problem,
If you try veiw a record and you click the image on the right, it pulls up the wrong record.
Any idea as to why??
Thanks in advance.
pfrules
Again,
I fixed my issue by removing the example Random methods from TableBean and change the class to... This works....
==============
TableBean.java
-----------------
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ManagedBean;
@ManagedBean
@SessionScoped
public class TableBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = -6354969164694344839L;
private final static String[] colors;
private final static String[] manufacturers;
private List<Car> cars;
private Car selectedCar;
static {
colors = new String[10];
colors[0] = "Black";
colors[1] = "White";
colors[2] = "Green";
colors[3] = "Red";
colors[4] = "Blue";
colors[5] = "Orange";
colors[6] = "Silver";
colors[7] = "Yellow";
colors[8] = "Brown";
colors[9] = "Maroon";
manufacturers = new String[10];
manufacturers[0] = "Mercedes";
manufacturers[1] = "BMW";
manufacturers[2] = "Volvo";
manufacturers[3] = "Audi";
manufacturers[4] = "Renault";
manufacturers[5] = "Opel";
manufacturers[6] = "Volkswagen";
manufacturers[7] = "Chrysler";
manufacturers[8] = "Ferrari";
manufacturers[9] = "Ford";
}
public TableBean() {
cars = new ArrayList<Car>();
populateCars(cars, 5);
}
private void populateCars(List<Car> list, int size) {
list.add(new Car("111111",1999,"Tayota","White"));
list.add(new Car("222222",2000,"Ferari","Red"));
list.add(new Car("333333",2001,"Fiat","Blue"));
list.add(new Car("444444",2002,"Pontiac","Green"));
list.add(new Car("555555",1999,"Honda","Yellow"));
}
public Car getSelectedCar() {
return selectedCar;
}
public void setSelectedCar(Car selectedCar) {
this.selectedCar = selectedCar;
}
public List<Car> getCars() {
return cars;
}
}
I fixed my issue by removing the example Random methods from TableBean and change the class to... This works....
==============
TableBean.java
-----------------
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ManagedBean;
@ManagedBean
@SessionScoped
public class TableBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = -6354969164694344839L;
private final static String[] colors;
private final static String[] manufacturers;
private List<Car> cars;
private Car selectedCar;
static {
colors = new String[10];
colors[0] = "Black";
colors[1] = "White";
colors[2] = "Green";
colors[3] = "Red";
colors[4] = "Blue";
colors[5] = "Orange";
colors[6] = "Silver";
colors[7] = "Yellow";
colors[8] = "Brown";
colors[9] = "Maroon";
manufacturers = new String[10];
manufacturers[0] = "Mercedes";
manufacturers[1] = "BMW";
manufacturers[2] = "Volvo";
manufacturers[3] = "Audi";
manufacturers[4] = "Renault";
manufacturers[5] = "Opel";
manufacturers[6] = "Volkswagen";
manufacturers[7] = "Chrysler";
manufacturers[8] = "Ferrari";
manufacturers[9] = "Ford";
}
public TableBean() {
cars = new ArrayList<Car>();
populateCars(cars, 5);
}
private void populateCars(List<Car> list, int size) {
list.add(new Car("111111",1999,"Tayota","White"));
list.add(new Car("222222",2000,"Ferari","Red"));
list.add(new Car("333333",2001,"Fiat","Blue"));
list.add(new Car("444444",2002,"Pontiac","Green"));
list.add(new Car("555555",1999,"Honda","Yellow"));
}
public Car getSelectedCar() {
return selectedCar;
}
public void setSelectedCar(Car selectedCar) {
this.selectedCar = selectedCar;
}
public List<Car> getCars() {
return cars;
}
}
-
- Information
-
Who is online
Users browsing this forum: No registered users and 55 guests