DataTable Sorting

UI Components for JSF
Post Reply
User avatar
benpad
Posts: 58
Joined: 24 Jun 2010, 04:54
Location: Makati, City Philippines
Contact:

07 Jul 2010, 07:03

Hello,

I wonder why the sample in the showcase regards to ajax sorting doesn't have sortBy or sortFunction in attribute in columns?

http://www.primefaces.org:8080/prime-sh ... leAjax.jsf
PrimeFaces 2.1
JSF 2.0
GlassFish 3 Server
Mojarra 2.0.2

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

07 Jul 2010, 09:38

this is the correct XHTML code for the DataTable - Ajax Pagination/Sorting showcase

Code: Select all

<h:form>
 
	<p:dataTable var="car" value="#{tableBean.cars}" dynamic="true"
		paginator="true" rows="10">
		<p:column sortBy="#{car.model}">
			<f:facet name="header">
				<h:outputText value="Model" />
			</f:facet>
			<h:outputText value="#{car.model}" />
		</p:column>

		<p:column sortBy="#{car.year}">
			<f:facet name="header">
				<h:outputText value="Year" />
			</f:facet>
			<h:outputText value="#{car.year}" />
		</p:column>

		<p:column sortBy="#{car.manufacturer}">
			<f:facet name="header">
				<h:outputText value="Manufacturer" />
			</f:facet>
			<h:outputText value="#{car.manufacturer}" />
		</p:column>

		<p:column sortBy="#{car.color}">
			<f:facet name="header">
				<h:outputText value="Color" />
			</f:facet>
			<h:outputText value="#{car.color}" />
		</p:column>
	</p:dataTable>

</h:form>
JSF-2.0, mojarra-2.0.2-FCS and PrimeFaces-2.1 on GlassFish v3.0.1 (build 22)

User avatar
benpad
Posts: 58
Joined: 24 Jun 2010, 04:54
Location: Makati, City Philippines
Contact:

07 Jul 2010, 09:44

Thank you michiel,

I tried that code and I'm getting this weird behavior on sorting:

1. When I press the table header to sort, the data sorts accordingly.
2. When I press it again, the data will be gone and to other columns with sortBy attribute.

My dataTable is set to dynamic = true. I just want to ask if I'm missing something here why the data is gone for the second hit in sorting.

Thank you.
PrimeFaces 2.1
JSF 2.0
GlassFish 3 Server
Mojarra 2.0.2

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

07 Jul 2010, 09:55

you need to provide some more info.

are you getting any error?
is the showcase working for you?
any code (xhtml and managedBean), also the java code for the Object your trying to show/sort (like 'car' in the showcase)?
JSF-2.0, mojarra-2.0.2-FCS and PrimeFaces-2.1 on GlassFish v3.0.1 (build 22)

User avatar
benpad
Posts: 58
Joined: 24 Jun 2010, 04:54
Location: Makati, City Philippines
Contact:

07 Jul 2010, 10:02

Here's my xhtml:

Code: Select all

<h:form>
    <p:dataTable var="car" value="#{carBean.cars}"
                 rows="10"
                 paginator="true" 
                 dynamic="true">

        <p:column sortBy="#{car.model}">
            <f:facet name="header">
                <h:outputText value="Model"/>
            </f:facet>
            <h:outputText value="#{car.model}"/>
        </p:column>

    </p:dataTable>
</h:form>
The bean:

Code: Select all

@ManagedBean(name = "carBean")
@SessionScoped
public class CarBean implements Serializable {

    private List<Car> cars;
    public List<Car> getCars() { return cars; }
    public void setCars(List<Car> cars) { this.cars = cars; }

    private Car car;
    public Car getCar() { return car; }
    public void setCar(Car car) { this.car = car; }

    public CarBean() {
        cars = new ArrayList<Car>();
        populateCars(cars, 35);
    }

    private void populateCars(List<Car> cars, int size) {
        for (int i = 0; i < size; i++) {
            cars.add(new Car(createModel(i), 2010, createManufacturer(i), createColor(i)));
        }
    }

    private String createModel(int i) {
        return "model " + i * (Math.random() * 10);
    }

    private String createManufacturer(int i) {
        return "manufacturer " + i * (Math.random() * 10);
    }

    private String createColor(int i) {
        return "color #" + i + (Math.random() * 10);
    }

}
Thank you.
PrimeFaces 2.1
JSF 2.0
GlassFish 3 Server
Mojarra 2.0.2

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

07 Jul 2010, 13:32

Don't forgot to implement Serializable on your business model objects. (Car in this case)

view also http://primefaces.prime.com.tr/forum/vi ... f=3&t=2497
JSF-2.0, mojarra-2.0.2-FCS and PrimeFaces-2.1 on GlassFish v3.0.1 (build 22)

User avatar
benpad
Posts: 58
Joined: 24 Jun 2010, 04:54
Location: Makati, City Philippines
Contact:

07 Jul 2010, 15:00

Thank you michiel. My problem solved. Now I have another problem. Remote sorting doesn't work with LazyModel implemented bean.
PrimeFaces 2.1
JSF 2.0
GlassFish 3 Server
Mojarra 2.0.2

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

08 Jul 2010, 16:04

Lazy sorting is not supported yet but it will be in 2.1.1 release which is due August.

User avatar
benpad
Posts: 58
Joined: 24 Jun 2010, 04:54
Location: Makati, City Philippines
Contact:

08 Jul 2010, 17:10

My project deadline is on August. :( Unlucky me.
PrimeFaces 2.1
JSF 2.0
GlassFish 3 Server
Mojarra 2.0.2

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 44 guests