• Post Reply Bookmark Topic Watch Topic
  • New Topic

sortable datatable not working

 
baabs
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi baabs,
I am also facing the same problem. If you have got a solution, could please share.

Thanks,
Yellap
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
vishwa venkat
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!