aspose file tools
The moose likes JSF and the fly likes sortable datatable not working Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "sortable datatable not working " Watch "sortable datatable not working " New topic
Author

sortable datatable not working

baabs
Greenhorn

Joined: Jun 10, 2006
Posts: 5
hi,

i'm using datatable with sorting,i have implement the following code,but i got the error.please any one can help me .....................

************
my jsp code
***********

<t:dataTable id="list" value="#{assetgroupindex.list}" var="list" rows="10" sortColumn="#{assetgroupindex.column}"

sortAscending="#{assetgroupindex.ascending}" preserveDataModel="true" preserveSort="true">

<h:column>
<f:facet name="header">
<t:commandSortHeader columnName="assetGroupCode" arrow="true">
<hutputText value="#{bondsproperty.assetgroup_assetgroupCode_label}" styleClass="portlet-index-header"/>
</t:commandSortHeader>
</f:facet>
<hutputText value="#{list.assetGroupCode}" styleClass="portlet-form-field-label"/>
</h:column>

<h:column>
<f:facet name="header">
<hutputText value="#{bondsproperty.assetgroup_assetgroupName_label}" styleClass="portlet-index-header"/>
</f:facet>
<hutputText value="#{list.assetGroupName}" styleClass="portlet-form-field-label"/>
</h:column>
</t:dataTable>


*********************
my backing bean code
*********************
public class AssetGroupIndex extends GenericBean{
private String assetGroupCode;
private String assetGroupName;

private String column;
private boolean ascending;

private List list ;

public AssetGroupIndex(){
column = "assetGroupCode";
ascending = true;
}

protected void sort(final String column, final boolean ascending){
Comparator comparator = new Comparator(){
public int compare(Object o1, Object o2){
AssetGroupIndex c1 = (AssetGroupIndex)o1;
AssetGroupIndex c2 = (AssetGroupIndex)o2;

if(column == null)
{
return 0;
}

if(column.equals("assetGroupCode"))
{

return ascending ? c1.getAssetGroupCode().compareTo(c2.getAssetGroupCode()) : c2.getAssetGroupCode().compareTo(c1.getAssetGroupCode());
}
else return 0;
}
};

Collections.sort(list,comparator);


}


public void setAssetGroupCode(String assetGroupCode) {
this.assetGroupCode=assetGroupCode;
}


public String getAssetGroupCode(){
return assetGroupCode;
}


public void setAssetGroupName(String assetGroupName) {
this.assetGroupName=assetGroupName;
}

public String getAssetGroupName(){
return assetGroupName;
}

******************************
This List coming from database
******************************
public List getList() {
List list =null ;
try {
list =(List)retrieveAll();

sort(getColumn(), isAscending());

}catch (Exception e) {;
logger.error(e);
}
return list;
}


public void setList(List list) {
this.list = list;
}


public String getColumn() {

return column;
}



public void setColumn(String column) {
this.column = column;
}



public boolean isAscending() {
return ascending;
}



public void setAscending(boolean ascending) {
this.ascending = ascending;
}


}

regards
Babu
Yellapa Adepu
Ranch Hand

Joined: Jan 17, 2006
Posts: 34
Hi baabs,
I am also facing the same problem. If you have got a solution, could please share.

Thanks,
Yellap


Yellapa Adepu<br />SCEA
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56189
    
  13

"baabs", you have previously been warned on one or more occasions regarding adjusting your display name to meet JavaRanch standards. This is not optional. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it prior to your next post.

Your display name must be a first and a last name separated by a space character, and must not be obviously fictitious. Initials for a last name are not acceptable.

Be aware that accounts with invalid display names are removed.

bear
JavaRanch Sheriff


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
vishwa venkat
Ranch Hand

Joined: Nov 22, 2003
Posts: 185
have you guys referred to the book "Mastering Javaserver faces" by Wily publications. This book contains a good example of datatable component with sort options.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sortable datatable not working
 
Similar Threads
how to set and get h:selectBooleanCheckbox value in h:datatabel
Tomahawk dataTable sorting problem
Problem with column sort in myFaces dataTable
datatable - row colors
Input row select on data table does not get called