我无法找到在获取数据表的过滤值后更新组件的方法。我尝试不同的方法:如何在数据表中找到新的过滤值黄页
测试1:我尝试使用
Filter
事件的行动,但该事件值的变化之前完成,所以我不能让我的计算新值测试2:我尝试使用
Filter
事件的监听器,但在AjaxBehaviorEvent
测试3我无法找到新的价值观:我尝试调用我的函数的过滤的二传手值,计算已完成但未更新...所以我尝试使用
RequestContext
的primefaces,但它也不起作用。
告诉我,如果你有一个想法解锁的一种方式,或提出新的解决方案=)
感谢您的帮助!
控制台返回,显示事件的顺序。
>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更容易 – Kukeltje
LazyDataModel更改获取/保存值而不是组件事件的方式,它如何帮助我在这里进行过滤? –