• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

sortable datatable not working

 
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">
<h:outputText value="#{bondsproperty.assetgroup_assetgroupCode_label}" styleClass="portlet-index-header"/>
</t:commandSortHeader>
</f:facet>
<h:outputText value="#{list.assetGroupCode}" styleClass="portlet-form-field-label"/>
</h:column>

<h:column>
<f:facet name="header">
<h:outputText value="#{bondsproperty.assetgroup_assetgroupName_label}" styleClass="portlet-index-header"/>
</f:facet>
<h:outputText 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
 
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
 
Marshal
Posts: 67478
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
 
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic