0

我有一张桌子显示。当用户单击标题时,我希望表格自行重组,并根据所选标题进行排序。再次单击同一标题,交换排序顺序 在表格中,有几个命令链接。

现在,问题如下

  1. 排序顺序的第一次更新发生,但再次单击标题不会交换顺序。
  2. 刷新表时,链接的值已更改,但链接仍映射到先前存在的对象

代码:

桌子:

<h:form title="table">
<h:dataTable value="#{employee.employeeList}" var="a"
    styleClass="order-table" headerClass="order-table-header"
    rowClasses="order-table-odd-row,order-table-even-row"
    style="width:100%">
<h:column>
<f:facet name="header"><h:commandLink value="Number" action="#{employee.sortByNumber()}" /></f:facet>
<h:commandLink value="#{a.number}" action="#{employee.setEmp(a)}" />
</h:column>
...
...
...
</h:dataTable>
</h:form>

员工豆:

public String filter = ""; //has getters and setters
public String order = ""; //has getters and setters
public static final String ORDER_ASCENDING = "asc";
public static final String ORDER_DESCENDING = "desc";
public static final String FILTER_NUMBER = "number";

public void sortByNumber(){
        if(filter.equals(FILTER_NUMBER)){
            swapOrder();
        }else{
            filter = FILTER_NUMBER;
            order = ORDER_ASCENDING;
        }
        refreshPage();
    }
public void swapOrder(){
        if(order.equals(ORDER_ASCENDING)){
            order = ORDER_DESCENDING;
        }else{
            order = ORDER_ASCENDING;
        }
    }
public void refreshPage(){
        FacesContext context = FacesContext.getCurrentInstance();
        String viewId = context.getViewRoot().getViewId();
        ViewHandler handler = context.getApplication().getViewHandler();
        UIViewRoot root = handler.createView(context, viewId);
        root.setViewId(viewId);
        context.setViewRoot(root);
    }

public String setEmp(Employee employee) {
        this.employee = employee;
        return "details"; //redirects to the details page where the employee set in  the previous line is used
    }
4

0 回答 0