Sort trouble in DataTable with date

UI Components for JSF
Post Reply
markusg
Posts: 4
Joined: 10 Dec 2009, 11:59

10 Dec 2009, 12:11

Hello,
I have a DataTable that displays a list of beans, one row for each and I would like it sortable on the client side, using Primefaces 1.0.0.RC.
All the columns are text except for one which is a date. When I set the date column to sortable it just displays "Invalid Date".
How can I fix this?

Here is the xhtml and java code for the relevant field:

xhtml:

Code: Select all

    <p:dataTable var="row" value="#{alarms}" >
...
      <p:column sortBy="#{row.time}" parser="date">
	<f:facet name="header">
	  <h:outputText value="Time (GMT)" />
	</f:facet>
	<h:outputText value="#{row.time}" />
      </p:column>
...
    </p:dataTable>
Java:

Code: Select all

	public Date getTime()
	{
		return time;
	}
	public void setTime(Date time)
	{
		this.time = time;
	}
Edit:
Forgot to mention that I know the value of time is never null because the bean also has this code at the top:

Code: Select all

	private Date time = new Date();

markusg
Posts: 4
Joined: 10 Dec 2009, 11:59

11 Dec 2009, 13:24

Shameless bump

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

11 Dec 2009, 15:07

Hi,

No need for shame

:) As you can see from the forum, there's high volume of support requests, since we try to help everyone it takes some time.

May I ask who gives that error? javascript when you try to sort it or java stack trace when you try to open the page?

markusg
Posts: 4
Joined: 10 Dec 2009, 11:59

11 Dec 2009, 15:48

cagatay.civici wrote:Hi,

No need for shame

:) As you can see from the forum, there's high volume of support requests, since we try to help everyone it takes some time.

May I ask who gives that error? javascript when you try to sort it or java stack trace when you try to open the page?
It is most likely in the javascript because there is no java stack trace.
But it happens right away, it is broken as soon as the page loads, regardless of whether a column header has been clicked or not.
Looking at the page source I can see something that looks like correct dates in a table, but they are displayed as "Invalid Date"

Code: Select all

...
<td>Tue Nov 24 00:00:00 CET 2009</td>
...
To give a little more information, this is running as a portlet in liferay version 5.2.3 and we are also using spring webflow.

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

11 Dec 2009, 16:12

For client side sorting DataTable parses that column information to javascript date type, I'm not sure if that text is supported by javascript. Do you have to use that format? If not using a formatter can fix it like;

Code: Select all

<h:outputText value="#{row.time}">
    <f:convertDateTime pattern="MM/dd/yyyy" />
</h:outputText>
I'm looking into this issue.

markusg
Posts: 4
Joined: 10 Dec 2009, 11:59

14 Dec 2009, 10:09

Thank you very much for your replies.

I have to use the ISO date format (yyyy-MM-dd) so I tried Date.parse on that in chrome, which worked fine. But alas, it did not work in firefox. An american date (MM/dd/yyyy) however, did work in firefox.
So I tried making the dates into properly formatted strings instead and tried to do this:

Code: Select all

				<p:column sortBy="#{row.timeStringAmerican}" parser="date">
					<f:facet name="header">
						<h:outputText value="Time (GMT)" />
					</f:facet>
					<h:outputText value="#{row.timeStringISO}" />
				</p:column>
But it still didn't work. It seems like the actual outputText has to be in a format the parser can understand?
That seems weird to me. If that is the case, then why do I even have to specify a separate value for the sortBy attribute?

I "solved" my issue by just sorting the dates as strings since ISO dates are ordered from most to least significant number in left to right order anyway so that works in my case.

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

14 Dec 2009, 11:49

Ok, glad you found a solution. sortBy is is for ajax sorting actually, we use that property to find out which field to use when sorting on server side with ajax. For client side it's just a flag marking that column as sortable. We tried to avoid adding a new attribute like sortable by reusing this sortBy attribute actually. Also I believe if you use a dynamic datatable, you can avoid client side javascript date parsing issues since PrimeFaces will sort dates for you on server side with ajax.

Javascript parseDate is supposed to support many different patterns actually, we'll investigate more. Thanks for your feedback!

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 25 guests