primefaces数据表过滤器在后续点击中不起作用

时间:2013-06-26 14:52:40

标签: java jsf primefaces

我有一个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演示中的逻辑相同。

1 个答案:

答案 0 :(得分:0)

此问题类似于以下问题:Ajax update doesn't work, when using filter on p:dataTable

在进行ajax调用后尝试调用任务Table.filter():

<p:ajax event="filter" update="@this" oncomplete="tasksTable.filter()" />