如何在数据表primefaces中获取新的过滤值

时间:2016-08-04 09:25:21

标签: jsf primefaces filter datatable

在获取数据表的过滤值后,我找不到更新组件的方法。我尝试了不同的方式:

  • 测试1:我尝试使用Filter事件的操作,但此事件在更改值之前完成,因此我无法使用新值进行计算

  • 测试2:我尝试使用Filter事件的监听器,但我在AjaxBehaviorEvent

  • 中找不到新值
  • 测试3:我尝试在过滤值的setter中调用我的函数,计算已完成但未更新...所以我尝试使用RequestContext的primefaces但它没有工作要么。

告诉我你是否有想法解锁一种方法,或提出新的解决方案=)

感谢您的帮助!

控制台返回,以显示事件的顺序。

>test 1
>test 2
>update other
>update filtered values
>test 3

HTML code:

<h:form id="form1">
    <p:dataTable var="_remontee" value="#{ConsultationSaisieBean.m_valuesInDataGrid}" 
    filteredValue="#{ConsultationSaisieBean.m_filteredValues}"  >

        <p:ajax event="filter"  listener="#{ConsultationSaisieBean.OnFilter}" 
        action="#{ConsultationSaisieBean.FilterAction}" update=":form2"/>

        <p:columns value="#{ConsultationSaisieBean.m_columns}" var="column" 
        filterBy="#{_remontee[column.property]}" filterMatchMode="contains">
            <f:facet name="header">
                <h:outputText value="#{column.header}" />
            </f:facet>
            <h:outputText value="#{_remontee[column.property]}" />
        </p:columns>
   </p:dataTable>
</h:form>

<h:form id="form2">
   <p:outputLabel id="other" value="#{ConsultationSaisieBean.m_serviceResult}" />
</h:form>

Java类:

/**
 * function of the filter event's action
 */
public void FilterAction()
{
    // TEST 1
    System.out.println("test 1");
    setM_consummableResult(Resultof(m_filteredValues))
}

/**
 * function of event's listener 
 */
public Map<String, Object>  OnFilter(AjaxBehaviorEvent p_event)
{
    // TEST 2
    System.out.println("test 2");
    setM_consummableResult(Resultof(m_filteredValues))

    // return values wanted by the event
    DataTable table = (DataTable) p_event.getSource();
    Map<String, Object> filters = table.getFilters();
    return filters;
}

/**
 * Setter of the filtered values
 */
public void setM_filteredValues(List<Map<String, String>> p_filteredValues)
{
    // UPDATE FILTERED VALUES
    System.out.println("update filtered values");

    super.setM_filteredValues(p_filteredValues);

    // TEST 3
    System.out.println("test 3");
    setM_consummableResult(Resultof(m_filteredValues))

    //Test to force update 
    RequestContext context = RequestContext.getCurrentInstance();
    context.addCallbackParam("saved", true); 
    context.update("form2:other");
}

/**
 * function to count the new result
 */
public void Resultof(List<Map<String, String>> p_filteredValues)
{
    /* calcul the new values */
}

/**
 * getter for update the other component
 */
public Double getM_consummableResult()
{
    return m_consummableResult;
    // UPDATE
    System.out.println("update other");
}

public List<Map<String, String>> getM_filteredValues()
{
    return m_filteredValues;
}

private void setM_consummableResult(Double m_consummableResult)
{
    this.m_consummableResult = m_consummableResult;
}

1 个答案:

答案 0 :(得分:1)

我和你有同样的问题。我已经解决了使用remotecommand ...

 <p:ajax event="filter" oncomplete="handleLoadStart();" update=":frm1:tablaFact :frm1:panelTotal"/>

...

 <p:remoteCommand id="rcom" name="loadRemoteContent" process="@this" update="panelTotal, tablaFact"  actionListener="#{listadoFacturasMB.filterListener2}"/>

...

  <h:outputScript id="waypointScript" target="body">  
     function handleLoadStart() {                     
                loadRemoteContent();                       
                }

 </h:outputScript>

...

 public void filterListener2() {
    try {
        if (filterFacturaUtilList != null) {
          //then filter is active, do something...
        }

    } catch (Exception e) {
        JsfUtil.addErrorMessage(e, "Error: filterListener() " + e.getMessage());
    }
}

filterFacturaUtilList是filteredValue