DataTable and Filter

UI Components for JSF
Post Reply
Alexandre
Posts: 16
Joined: 18 Jan 2011, 10:36

17 Mar 2011, 16:58

Hi, i m testing primefaces for Energie Company in FRANCE. I have probleme with datatable in lazy mode.

What steps will reproduce the problem?
On complex datatable exemple
1.Select a row.
2.Use a Filter
3.Select an other row.

What is the PrimeFaces version?
I test it with 2.2.1, 2.2.1-SNAPSHOT 2011-03-17, and primefaces 3.0.

What is the expected output? What do you see instead?
I see the first information of step 1 row.

Which JSF implementation with version are you using?(Mojarra or MyFaces)
Mojarra 2.1.1.B02

Which component libraries are you using in addition to PrimeFaces?
none

Which application server or servlet container are you using?
Tomcat 6
Primefaces 2.2.1

Alexandre
Posts: 16
Joined: 18 Jan 2011, 10:36

18 Mar 2011, 12:36

The code

car.java

Code: Select all

package org.primefaces.examples.view;

public class Car {

	private String model;
	private Integer year;
	private String manufacturer;
	private String color;

	public Car(String randomModel, Integer randomYear,
			String randomManufacturer, String randomColor) {
		this.model=randomModel;
		this.year=randomYear;
		this.manufacturer=randomManufacturer;
		this.color=randomColor;
	}

	public String getModel() {
		return model;
	}

	public void setModel(String model) {
		this.model = model;
	}

	public Integer getYear() {
		return year;
	}

	public void setYear(Integer 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;
	}

	

}

datatableComplex.xhtml

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	>
<h:head>

</h:head>
<h:body>
<h:form>  
  
    <p:dataTable
    			id="tableCars" 
    			var="car" 
    			value="#{tableBean.cars}" 
    			paginator="true" rows="10"
                selectionMode="single"
                selection="#{tableBean.selectedCar}"
                onRowSelectUpdate="display" 
                onRowSelectComplete="carDialog.show()" >  
  
        <f:facet name="header">  
            List of Cars   
        </f:facet>  
  
        <p:column sortBy="#{car.model}" filterBy="#{car.model}">  
            <f:facet name="header">  
                <h:outputText value="Model" />  
            </f:facet>  
            <h:outputText value="#{car.model}" />  
        </p:column>  
  
        <p:column sortBy="#{car.year}" filterBy="#{car.year}">  
            <f:facet name="header">  
                <h:outputText value="Year" />  
            </f:facet>  
            <h:outputText value="#{car.year}" />  
        </p:column>  
  
        <p:column sortBy="#{car.manufacturer}" filterBy="#{car.manufacturer}">  
            <f:facet name="header">  
                <h:outputText value="Manufacturer" />  
            </f:facet>  
            <h:outputText value="#{car.manufacturer}" />  
        </p:column>  
  
        <p:column sortBy="#{car.color}" filterBy="#{car.color}">  
            <f:facet name="header">  
                <h:outputText value="Color" />  
            </f:facet>  
            <h:outputText value="#{car.color}" />  
        </p:column>  
  
    </p:dataTable>  
  
    <p:dialog id="dialogCarInfo" header="Car Detail" widgetVar="carDialog" resizable="true"  
              width="200" >  
  
        <h:panelGrid id="display" columns="2" cellpadding="4">  
  
            <f:facet name="header">  
                <p:graphicImage value="/images/cars/#{tableBean.selectedCar.manufacturer}.jpg"/>  
            </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>
TableBean.java

Code: Select all

package org.primefaces.examples.view;   
  
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import javax.faces.bean.ManagedBean;

import org.primefaces.event.SelectEvent;
 
@ManagedBean
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;   
    private Random r=new Random(125); 
    
    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()));   
    }   
  
    private String getRandomModel() {
		return String.valueOf(r.nextInt(1000));
	}

	private String getRandomManufacturer() {
		return manufacturers[r.nextInt(9)];
	}

	private String getRandomColor() {

		return colors[r.nextInt(9)];
	}

	private Integer getRandomYear() {
    	return r.nextInt(2010);
	}

	public Car getSelectedCar() {   
        return selectedCar;   
    }   
    public void setSelectedCar(Car selectedCar) {   
        this.selectedCar = selectedCar;   
    }   
  
    public List<Car> getCars() {   
        return cars;   
    }   
    
}   

Primefaces 2.2.1

Alexandre
Posts: 16
Joined: 18 Jan 2011, 10:36

18 Mar 2011, 15:44

Ok i find it. bean must implements Serializable.
Primefaces 2.2.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 48 guests