Unable to get sortBy working in RichFaces 4

I follow this example: http://mkblog.exadel.com/2008/11/richfaces-built-in-sorting/

he said that arrows should appear next to the heading, and the user can click it to sort.

But I can’t get the arrow. You help to appreciate.

The code I'm using is:

newwonder.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:a4j="http://richfaces.org/a4j" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:rich="http://richfaces.org/rich"> <h:head> <title>Requirement Workflow</title> </h:head> <h:body> <rich:dataTable value="#{newWondersBean.sevenNewWonders}" var="wonder"> <rich:column sortBy="#{wonder.name}"> <f:facet name="header">Name</f:facet> <h:outputText value="#{wonder.name}" /> </rich:column> <rich:column sortBy="#{wonder.location}"> <f:facet name="header">Location</f:facet> <h:outputText value="#{wonder.location}" /> </rich:column> <rich:column> <f:facet name="header">Image</f:facet> <h:graphicImage url="#{wonder.imageUrl}" /> </rich:column> </rich:dataTable> </h:body> </html> 

NewWondersBean.java

  package wonder; import java.util.ArrayList; import javax.annotation.PostConstruct; import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; @ManagedBean @ViewScoped public class NewWondersBean { private ArrayList <Wonder> sevenNewWonders = new ArrayList <Wonder>(); @PostConstruct public void init () { sevenNewWonders = new ArrayList <Wonder>(); sevenNewWonders.add(new Wonder("Chichen Itza", "Mexico", "http://upload.wikimedia.org/wikipedia/commons/thumb/7/7a/Chichen-Itza-Castillo-Seen-From-East.JPG/90px-Chichen-Itza-Castillo-Seen-From-East.JPG")); sevenNewWonders.add(new Wonder("Christ the Redeemer", "Brazil", "http://upload.wikimedia.org/wikipedia/commons/thumb/5/50/CorcovadofotoRJ.jpg/90px-CorcovadofotoRJ.jpg")); sevenNewWonders.add(new Wonder("Colosseum", "Italy", "http://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Colosseum_in_Rome%2C_Italy_-_April_2007.jpg/90px-Colosseum_in_Rome%2C_Italy_-_April_2007.jpg")); sevenNewWonders.add(new Wonder("Great Wall of China", "China", "http://upload.wikimedia.org/wikipedia/commons/thumb/1/16/GreatWallNearBeijingWinter.jpg/90px-GreatWallNearBeijingWinter.jpg")); sevenNewWonders.add(new Wonder("Machu Picchu", "Peru", "http://upload.wikimedia.org/wikipedia/commons/thumb/1/13/Before_Machu_Picchu.jpg/90px-Before_Machu_Picchu.jpg")); sevenNewWonders.add(new Wonder("Petra", "Jordan", "http://upload.wikimedia.org/wikipedia/commons/thumb/0/06/PetraMonastery.JPG/90px-PetraMonastery.JPG")); sevenNewWonders.add(new Wonder("Taj Mahal", "India", "http://upload.wikimedia.org/wikipedia/commons/thumb/c/c8/Taj_Mahal_in_March_2004.jpg/90px-Taj_Mahal_in_March_2004.jpg")); } public ArrayList <Wonder> getSevenNewWonders() { return sevenNewWonders; } } 

Wonder.java

  package wonder; public class Wonder { public Wonder(String string, String string2, String string3) { // TODO Auto-generated constructor stub this.name = string; this.location = string2; this.imageUrl = string3; } public void setName(String name) { this.name = name; } public String getName() { return name; } public void setLocation(String location) { this.location = location; } public String getLocation() { return location; } public void setImageUrl(String imageUrl) { this.imageUrl = imageUrl; } public String getImageUrl() { return imageUrl; } private String name; private String location; private String imageUrl; } 
+4
source share
1 answer

As I understand it, sorting has changed using Richfaces 4.

You will need to have Map <String, SortOrder> , and you will need to add the attribute to your rich: column, where sortOrders is the Map above, and the provider is the key for this column.

  sortOrder="#{bean.sortsOrders['vendor']}"> 

After that, sorting is pretty much automatic magic, but the icon is also not in Richfaces 4, so you have to manually add them based on the SortOrder enumeration value for each column.

I think this is a pain and a step back from 3.x, but this is what is needed for the sorting to work.

You can always browse the RichFaces Showcase website for more information.

http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=extendedDataTable&sample=edt-sorting&skin=blueSky

EDIT: (January 2013)

With the upcoming RichFaces 4.3, automatic sorting is added back and will include arrows and what not. The link above should still have a good option for this.

EDIT: (September 2013) RF is now in version 4.3.4, and automatic sorting still fails. It works only with rich: extendedDataTable, but not with rich: dataTable

+6
source

Source: https://habr.com/ru/post/1401286/


All Articles