0

我有一个 primefaces 视图,在其中我使用下拉列表过滤特定列(任务状态)。当我第一次从过滤器列表中选择一个值时,过滤器工作正常,但在随后的过滤器选择中,表格没有刷新(我的视图已死)。

这是查看代码:

<p:dataTable id="tasksDataTable"
        var="cRTaskData" 
        value="#{taskCenterBean.cRTaskList}"
        widgetVar="tasksTable" 
        paginator="true"
        sortMode="multiple"
        filteredValue="#{taskCenterBean.cRTaskListFiltered}" 
        rows="10"
        paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
        rowsPerPageTemplate="10,15,20,30" 
        paginatorAlwaysVisible="false">
    <p:ajax event="filter" update="@this"/>
    <p:column sortBy="#{cRTaskData.taskId}" headerText="ID" style="width:40px;text-align:center;">
        <h:outputText value="#{cRTaskData.taskId}" />
    </p:column>

    <p:column filterBy="#{cRTaskData.status}" 
            filterMatchMode="exact" 
            filterOptions="#{taskCenterBean.cRTaskListOptions}" 
            headerText="Task Status" style="width:110px;text-align:center;">
        <h:outputText value="#{cRTaskData.status}" />
    </p:column>
    ...
    <p:column style="width:90px;text-align:center;">
        <p:commandButton value="View" 
            action="#{imageBrowserBean.openTaskInEditor(cRTaskData.taskId)}"                                        
            icon="ui-icon-image" />                     
    </p:column>
    ...
</p:dataTable>

这里是相关的后台 bean 代码:

@ManagedBean(name = "taskCenterBean")
@ViewScoped
public class TaskCenterBean implements Serializable  {
    private final static String[] cRTaskStatuses = {"Open","Submitted","Closed","Conflict"};
    private List<CRImageData>   cRTaskList;
    private List<CRImageData>   cRTaskListFiltered;
    private SelectItem[]        cRTaskListOptions;

    public List<CRImageData> getcRTaskList() {
    return cRTaskList;
    }

    public List<CRImageData> getcRTaskListFiltered() {
    return cRTaskListFiltered;
    }

    public void setcRTaskListFiltered(List<CRImageData> cRTaskListFiltered) {
    this.cRTaskListFiltered = cRTaskListFiltered;
    }

    public SelectItem[] getcRTaskListOptions() {
    return cRTaskListOptions;
    }

    private SelectItem[] createFilterOptions(String[] data)  {  
        SelectItem[] options = new SelectItem[data.length + 1];  

        options[0] = new SelectItem("", "Select");  
        for(int i = 0; i < data.length; i++) {  
            options[i + 1] = new SelectItem(data[i], data[i]);  
        }  

        return options;  
    } 

    @SuppressWarnings("unchecked")
    public TaskCenterBean(){
        Session session = HibernateUtil.getSessionFactory().openSession();
        Criteria criteria = session.createCriteria(CRTask.class);
        criteria.add(Restrictions.eq("reviewerId", ConfigOptionsBean.getCurrentUser().getUserId()));
        cRTaskList = criteria.list();
        session.close();    

        cRTaskListOptions = (SelectItem[]) createFilterOptions(cRTaskStatuses);
    }
    ...
}

有什么想法我一直在想念吗?该逻辑与相关 primefaces 演示中的逻辑相同。

4

1 回答 1

0

这个问题类似于这个问题:Ajax update doesn't work, when using filter on p:dataTable

在 ajax 调用后尝试调用 tasksTable.filter():

<p:ajax event="filter" update="@this" oncomplete="tasksTable.filter()" />
于 2013-06-27T22:43:12.833 回答