English 中文(简体)
冰面3.0 ace:数据 表一栏,以实例
原标题:icefaces 3.0 ace:dataTable sorting column,need example

I need an example for sorting a column in ace:dataTable, i don t know how to use sortBy + sortFunction . thanks

最佳回答

<ui:param name="title" value="#{msgs[dataTableSorting.title]}"/>
<ui:param name="description" value="#{msgs[dataTableSorting.description]}"/>
<ui:param name="resourceValue" value="#{dataTableSorting.exampleResource}"/>

<ui:param name="wikiResources" value="#{dataTableResources.wikiResources}"/>
<ui:param name="tldResources" value="#{dataTableResources.tldResources}"/>

<ui:define name="example">
    <h:form id="form">
       <ace:dataTable id="carTable"
                      value="#{dataTableSort.carsData}"
                      var="car">
           <ace:column id="id" headerText="ID" sortBy="#{car.id}">
                <h:outputText id="idCell" value="#{car.id}"/>
            </ace:column>
            <ace:column id="name" headerText="Name" sortBy="#{car.name}">
                <h:outputText id="nameCell" value="#{car.name}"/>
            </ace:column>
            <ace:column id="chassis" headerText="Chassis" sortBy="#{car.chassis}" >
                <h:outputText id="chassisCell" value="#{car.chassis}"/>
            </ace:column>
            <ace:column id="weight" headerText="Weight (lbs)" sortBy="#{car.weight}">
                <h:outputText id="weightCell" value="#{car.weight}"/>
            </ace:column>
            <ace:column id="accel" headerText="Accel" sortBy="#{car.acceleration}" >
                <h:outputText id="accelCell" value="#{car.acceleration}"/>
            </ace:column>
            <ace:column id="mpg" headerText="MPG" sortBy="#{car.mpg}">
                <h:outputText id="mpgCell" value="#{car.mpg}"/>
            </ace:column>
            <ace:column id="cost" headerText="Cost" sortBy="#{car.cost}">
                <h:outputText id="costCell" value="#{car.cost}">
                    <f:convertNumber type="currency"
                                     currencySymbol="$"
                                     groupingUsed="true"
                                     minFractionDigits="2"
                                     maxFractionDigits="2"/>
                </h:outputText>
            </ace:column>
        </ace:dataTable>
    </h:form>
</ui:define>

参考——icefaces-showcase

问题回答

So my friend found the solution:

In the collectionBean :

private Comparator<String> vNoComparator = new Comparator<String>(){ 

         public int compare(String iRec1, String iRec2){
              if(iRec1==null || iRec2==null)
              {
                    if(iRec1==null && iRec2==null)
                          return 0;
                    if(iRec1==null)
                          return -1;
                    return 1;
              } 

              long vNumber1=  Long.parseLong(iRec1) ;
              long vNumber2= Long.parseLong(iRec2);
              if(vNumber1>vNumber2)
                    return 1;
              else if(vNumber1<vNumber2)
                    return -1;
              else        
                    return 0; 
        }
  };

比较法的类型是按我们分类的属性类型,在这种情况下是记录。 无

public Comparator<String> getvNoComparator() {
        return vNoComparator;
  }
  public void setvNoComparator(Comparator<String> vNoComparator) {
        this.vNoComparator = vNoComparator;
  }

In .xhtml

  <ace:dataTable
  value="#{eITDocumentsCollectionBean.AEITDocumentsItems}"
  var="eITDocumentsItemBean" …..
  <ace:column
  headerText="#{eITDocumentsCollectionBean.ARecordNumberColumnName}"
  sortBy="#{eITDocumentsItemBean.ARecordNo}" 
  sortFunction="#{eITDocumentsCollectionBean.vNoComparator}">

ARecordNo= the attribute in the ItemBean to sort by it vNoComparator= the Comparator I create





相关问题
JSF redirect doesn t work

I have a problem with redirecting a page in my JSF application. My navigation rule look like this : <navigation-rule> <from-view-id>/index.xhtml</from-view-id> <...

Get JSF managed bean by name in any Servlet related class

I m trying to write a custom servlet (for AJAX/JSON) in which I would like to reference my @ManagedBeans by name. I m hoping to map: http://host/app/myBean/myProperty to: @ManagedBean(name="myBean"...

JSF2 - what scope for f:ajax elements?

I have this form: <h:form> <h:outputText value="Tag:" /> <h:inputText value="#{entryRecorder.tag}"> <f:ajax render="category" /> </h:inputText> ...

Modifying JSF Component Tree in PhaseListener

I m having an issue. I ve implemented a PhaseListener, which is meant to add a style class to any UIInput components in the tree that have messages attached to them, and removes the style class if it ...

JSF 2 - clearing component attributes on page load?

The real question: Is there a way to clear certain attributes for all components on an initial page load? Background info: In my application, I have a JSF 2.0 frontend layer that speaks to a service ...

JSF2 - backed by EJB or ManagedBean?

As I am learning JSF2, I realized I am not sure what the backing components should be. From design point of view, what is the difference between EJBs and @ManagedBeans? In the end I am going to use ...

热门标签