RichFaces extendedDataTable禁用排序

时间:2014-12-09 11:48:09

标签: jsf richfaces

我遇到了在点击按钮时禁用RichFaces按列排序的问题。 也许有人可以提供帮助

我有AlertsList数据表:

<rich:extendedDataTable id="#{module}AlertsList"
                            tableState="#{alertsController.dataModel.tableState}"
                            enableContextMenu="false"
                            height="220px"
                            sortMode="single"
                            value="#{alertsController.dataModel}"
                            var="alert" width="100%"
                            selection="#{alertsController.selection}"
                            reRender="#{module}AlertsListDatascroller"
                            rows="#{alertsController.dataModel.rowsPerPage}"
                            binding="#{alertsController.dataModel.extandetDataTable}"
                            rowClasses="evenRow,oddRow">
        ......                  
        <rich:column sortBy="#{alert.lockedByUsername}" width="7%"
                     style="#{(not empty alert.first4OfLockedByUsername and (alertsController.dataModel.selectedItem != alert)) ? 'background-color: darkgray' : ((alert.action != null and alert.action.classificationTypeEntity.classificationType eq 'POSTPONED') ? 'background-color: thistle' : '')}"
                     label="#{message['alertsnalysis.alertList.table.lock']}"
                     selfSorted="#{currentUser.authorities['SVWI_MODIFICATION']}"
                     id="#{module}AL_lockedByUsername">
            <f:facet name="header">#{message['alertsnalysis.alertList.table.lock']}</f:facet>
            <h:outputText value="#{alert.first4OfLockedByUsername}" />
        </rich:column>
        ......
        <rich:column sortBy="#{alert.id}" width="5%"
                     style="#{(not empty alert.first4OfLockedByUsername and (alertsController.dataModel.selectedItem != alert)) ? 'background-color: darkgray' : ((alert.action != null and alert.action.classificationTypeEntity.classificationType eq 'POSTPONED') ? 'background-color: thistle' : '')}"
                     label="#{message['alertsnalysis.alertList.table.id']}"
                     selfSorted="#{currentUser.authorities['SVWI_MODIFICATION']}"
                    id="#{module}AL_id">
            <f:facet name="header">#{message['alertsnalysis.alertList.table.id']}</f:facet>
            <h:outputText value="#{alert.id}" />
        </rich:column>
        ....
        <rich:datascroller id="#{module}AlertsListDatascroller" for="#{module}AlertsList" ajaxSingle="false" page="#{alertsController.dataModel.currentPage}"></rich:datascroller>

所以我添加了按钮来一次更改3个列的soring表结果,因为我当前的实现我无法通过单击不同的列标题排序数据(不接受sortMode =“multiply”的方式):

<h:form id="buttonReset">           
        <h:panelGrid columns="2">
            <a4j:commandButton id="resetSortingButton" styleClass="FatButtonStyle"  reRender="#{module}AlertsList"
                               action="#{alertsController.dataModel.defaultSortField}" value="Default Sorting"/>
        </h:panelGrid>



    </h:form>

我也实现了可修改:

public abstract class TableDataModel<T, U> extends SerializableDataModel implements Modifiable, Serializable {  
    ...
    protected String sortField = null;
    ..
    public void defaultSortField(){ // call on button "Default Sorting" click action
        this.sortField  = "default";  //set field to default
        this.detached = false;
        this.defaultFlag = true;
        this.i = 0;
    }
    ...
    @Override
    public void walk(final FacesContext context, final DataVisitor visitor, final Range range, final Object argument)
            throws IOException {
        final int firstRow = ((SequenceRange) range).getFirstRow();
        final int numberOfRows = ((SequenceRange) range).getRows();
        if (detached) {
            for (final U key : wrappedKeys) {
                setRowKey(key);
                visitor.process(context, key, argument);
            }
        } else {
            List<T> list = Collections.<T>emptyList();
            if (rangeChanged((SequenceRange) range) || sortChanged(sortField) || filterMapChanged(filterMap) || descChanged(descending) || ((MethodReRendering) this).getReRenderingEnabled()) {
                lastRange = (SequenceRange) range;
                lastSortField = sortField;
                lastFilterMap = new HashMap<String, Object>(filterMap);
                lastDescending = descending;
                ((MethodReRendering) this).setReRenderingEnabled(false);
                list = findObjects(firstRow, numberOfRows, sortField, filterMap, descending); //in findObjects() checking if sortField == "default", then sorting by 3 columns, else by column in field value
                wrappedKeys = new CopyOnWriteArrayList<U>();
                for (final T object : list) {
                    wrappedKeys.add(getId(object));
                    wrappedData.put(getId(object), object);
                    visitor.process(context, getId(object), argument);
                }
            } else {
                for (U id :wrappedKeys)
                    visitor.process(context, id, argument);
            }
        }
    }
    ...

    public void modify(List<FilterField> filterFields, List<SortField2> sortFields) {
        filterMap.clear();
        SortField2 sortField2 = null;

        String expressionStr = null;
        ExtendedFilterField extendedFilterField = null;
        String value = null;
        Expression expression = null;
        if (sortFields != null && !sortFields.isEmpty()) {
            sortField2 = sortFields.get(0);
            expression = sortField2.getExpression();
            ......
    }
    ...
}

问题是,当我单击我的btn时,我更改了sortField值,并且walk()方法将按3列数据排序的新数据返回到我的表中(请参阅findObjects(firstRow,numberOfRows,sortField,filterMap,descending);)。 一切正常。

但是在我的页面上我仍然可以看到(通过图标或者如果我刷新我的页面它调用带有List sortFields参数==“alertId”的modify()方法),这意味着仍然按alertId列排序的数据,但是实现了新的排序。我需要将什么逻辑添加到我的defaultSortField()方法(调用“默认排序”按钮单击),以通过alertId列禁用排序?enter image description here

UPDATE1: 添加了我的extendedDataTable到属性的绑定: 但也许有人知道如何禁用当前排序?      UIExtendedDataTable extandetDataTable = null;

    public void setExtandetDataTable(UIExtendedDataTable extandetDataTable) {
        this.extandetDataTable = extandetDataTable;
        List<SortField2>  sortField2s = extandetDataTable.getSortFields();
        SortField2 sortField2;
    }

    public UIExtendedDataTable getExtandetDataTable() {
        return extandetDataTable;
    }

1 个答案:

答案 0 :(得分:0)

为什么不能使用sortMode=multi

该表还有sortPriority - 用于排序的id列表,我假设你没有将列的id添加到sortPriority,因此它按照那里的id排序。处理在org.richfaces.renderkit.SortingFilteringRowsRenderer.decodeSorting()完成。

编辑:如果您要禁用排序,可以在rich:列上设置sortType="custom",但我不知道这是否会影响您的实施。