【问题标题】:How can I get new filtered values in a datatable primefaces如何在数据表 primefaces 中获取新的过滤值
【发布时间】:2016-12-10 08:20:33
【问题描述】:

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

  • 测试1:我尝试使用Filter事件的动作,但是这个事件是在值改变之前完成的,所以我不能用新值进行计算

  • 测试 2:我尝试使用 Filter 事件的侦听器,但在 AjaxBehaviorEvent 中找不到新值

  • 测试 3:我尝试在过滤值的设置器中调用我的函数,计算完成但未更新...所以我尝试使用 primefaces 的RequestContext 但它也不起作用.

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

感谢您的帮助!

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

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

HTML 代码:

<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;
}

【问题讨论】:

  • 使用 LazyDataModel,更简单
  • LazyDataModel 改变了获取/保存值而不是组件事件的方式,它如何帮助我在这里进行过滤?

标签: jsf primefaces filter datatable


【解决方案1】:

我遇到了和你一样的问题。我已经使用远程命令解决了...

 <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 是一个过滤值

【讨论】:

    猜你喜欢
    • 2015-04-10
    • 2016-08-09
    • 2014-03-01
    • 1970-01-01
    • 2013-08-01
    • 2013-07-30
    • 2014-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多