【问题标题】:Primefaces filterBy and sortBy are empty and EL not being evaluatedPrimefaces filterBy 和 sortBy 是空的,EL 没有被评估
【发布时间】:2017-07-06 22:14:46
【问题描述】:

我只是将我的 Primefaces 列标签放在一个带标签的包装器中,如下所示,但是,sortBy 和 filterBy EL 表达式没有被正确计算,也没有被传递给我的 LazyModel 中的 load 方法。

基本上,我有以下标签 ex:column:

<ui:composition
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"  
xmlns:p="http://primefaces.org/ui"
xmlns:ang="http://ang.com/jsf/facelets">

<p:column headerText="#{label}" sortable="#{sort}" sortBy="#{property}" filterBy="#{property}" filterable="#{filter}" filterMatchMode="#{filterMatchMode}">
    <h:outputText value="#{property}" />
</p:column>

在我的主要代码中,我正在执行以下操作:

<p:dataTable id="mainTable" widgetVar="tblTable" var="c" 
      value="#{applicationBean.lazyModel}" lazy="true" 
      paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" 
       paginator="true" rows="10" style="margin-bottom:20px" 
       selectionMode="single" selection="#{applicationBean.selected}"
       paginatorPosition="bottom" rowKey="#{c.id}">

      <ex:column label="First Name" property="#{c.firstName}" 
          filter="true" sort="true" filterMatchMode="contains" />

但是,当我在延迟加载 bean 中调用我的方法加载数据时,sortBy 和 filterBy 列作为“property”而不是“firstName”传递。

public List<T> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,Object> filters)

任何想法为什么没有在标签内的 filterBy 和 sortBy 中计算 EL 表达式?

仅供参考,该列已正确呈现。我可以看到表格中的所有内容,但是当我单击排序或筛选时,我得到属性不存在的异常。

我尝试使用 field="#{property}" 而不是 sortBy 和 filterBy,但是,它可以正常工作 用于排序;当我使用 field 属性时,filter by 仍然为空。

【问题讨论】:

  • 尝试将您的属性拆分为beanfield,以防止在您将EL 传递给组件时对其进行评估。在您的 XHTML 中使用 bean="#{c}" field="firstName",在您的组件中使用 sortyBy="#{bean[field]}"
  • Jasper,请注意 Bean 本身并不持有该字段。它是从表中派生的 var。尽管如此,我试过了。方法 load 现在正在接收字符串“bean[field]”。表达式仍未被计算。 XHTML: bean="#{c}" field="firstName";组件:filterBy="#{bean[field]}" --> 使用 String = bean[field] 调用 load 而不是评估 EL 表达式。我也试过 filterBy="#{field}" 并且我的方法接收字符串“field”而不是“firstName”。
  • Jasper,使用你的想法,我得到了以下答案: 1-拆分 var 和字段名称; 2-在字段变量中插入字段名称。 XHTML: var="#{c}" field="firstName";组件: field="#{field}" sortBy="#{field}" filterBy="#{field}" 。 “场”是这里最重要的部分;如果您不使用它,它将无法正常工作。

标签: jsf primefaces jsf-2


【解决方案1】:

解决方案

确保您的标签使用 3 个元素:field、sortBy 和 filterBy;所有这些元素只接收字段的名称,而不是 var/bean。

XHTML:

<ex:column label="First Name" var="#{c}" field="firstName" 
     filter="true" sort="true" filterMatchMode="contains" />

组件:

<p:column headerText="#{label}" field="#{field}" sortBy="#{field}"
    filterBy="#{field}" sortable="#{sort}" filterable="#{filter}"
    filterMatchMode="#{filterMatchMode}">
        <h:outputText value="#{var[field]}" />
</p:column>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-29
    • 1970-01-01
    • 1970-01-01
    • 2020-07-30
    • 2011-04-18
    • 1970-01-01
    相关资源
    最近更新 更多