File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Sorting in h:dataTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Sorting in h:dataTable" Watch "Sorting in h:dataTable" New topic

Sorting in h:dataTable

Karthik Krishna

Joined: Sep 02, 2008
Posts: 11

I have this jsf datatable:

<h:dataTable id="UserList" headerClass="headerClass"
rowClasses="tableOddRow, tableEvenRow" styleClass="dataTable"

<f:facet name="header">
<hutputText value="User Id" />
<hutputText value="#{bean.userId}" />

I am looking to sort it by the parameter "User Id" without sorting the
list in the bean.
How could I achieve it ? I am using JSF 1.1 .Could anyone please help ?

Pass on the knowledge!!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

The stock JSF datatable control doesn't support column sorting. You'll need an extended datatable control like the one that Tomahawk provides.

Of course if you're talking a LARGE collection such as a view into a database that's going to span multiple display pages, the rules are different, because at that level, you should have used a SQL with ordering.

An IDE is no substitute for an Intelligent Developer.
Karthik Krishna

Joined: Sep 02, 2008
Posts: 11
Hi Tim,

I have tried using Tomohawk 1.1.3 along with myfaces-impl-1.1.4 and myfaces-api-1.1.4 but it does not solve my issue. The issue being trying to use <t:dataTable to work with JSF 1.1 so that I could sort the list and provide the user with a capability of sorting when they click any header on the list.

The issues I have been facing is :

1)using Tomahawk 1.1.3,myfaces-impl-1.1.4,myfaces-api-1.1.4 instead of Tomahawk 1.0 screws up my existing application i.e I keep getting application error. I cannot chase those error because they are far too many and it would be time consuming to fix those than get the sorting feature working.

2) Using <display:table the issue is that say I have 3 JSPs namely

A.jsp , B.jsp , C.jsp

A.jsp is the main page and B.jsp, C.jsp are tabbed pane ( using <corejsf:tabpane> tag ) .

A.jsp uses :

<h:form id MainInfo>
<f:subview id = TabInfo >

<h:panelGrid width="100%"
<corejsf:tabbedPane id="TabPaneNew"
tabClass="coreJsfTab" selectedTabClass="coreJsfSelectedTab">
<f:selectItems value="#{tabPagesBean.showTabs}" />


B.jsp and C.jsp are tabbed panes.

To get the <display:table to render in B.jsp and C.jsp it says you need to wrap it in a <h:form > </h:form>. I wrapped the whole information in B.jsp with the <h:form > </h:form> tag, when i click either the C tab or click the B tab I get the following error msg :

TabInfo.MainInfo.TabPaneNew in null or not an object

I know we cannot use a <h: form > within a <h:form> but how could i get this working?
S Das

Joined: Nov 01, 2008
Posts: 3
Hi Karthik,

Try JBoss Richface JSF component. It has a lot of cool components to use. Here is the site for all component demo:
Expand the Data Iteration panel on the left and the last example is for data sorting.
A simple tag attribute will bring in the sort icon on the screen and also sort the data based on the field you mention. Be little careful to select the Richface version if you are downloading it. The latest 3.2 works with JSF 1.2. Download any of the previous versions.

Thanks,<br />Sudipto<br /> <br />"Build the Java Community"
I agree. Here's the link:
subject: Sorting in h:dataTable
It's not a secret anymore!