简体   繁体   English

排序参数未正确传递给延迟加载 Icefaces ace:dataTable

[英]Sorting parameters not passed correctly to a lazy loading Icefaces ace:dataTable

I'm trying to implement lazy loading in an ace:dataTable.我正在尝试在 ace:dataTable 中实现延迟加载。 My web application has quite a lot of tables, so I've tried to reduce redundancy by using templates for the columns.我的 web 应用程序有很多表,因此我尝试通过为列使用模板来减少冗余。 Currently my tables look like this:目前我的表是这样的:

Datatable in my xhtml page我的 xhtml 页面中的数据表

<ace:dataTable 
    id="produktdatenTabelle"
        value="#{produktdatenBean.lazyModel}"
        var="row"
        rows="20"
        paginator="true"
        paginatorPosition="bottom"
        paginatorAlwaysVisible="true"
        lazy="true">

    <ui:include src="/resources/aceDataTable/column.xhtml">
        <ui:param name="title" value="ID" />
        <ui:param name="value" value="#{row.id}" />
    </ui:include>

    <ui:include src="/resources/aceDataTable/column.xhtml">
        <ui:param name="title" value="Description" />
        <ui:param name="value" value="#{row.description}" />
    </ui:include>

</ace:dataTable>

column.xhtml列.xhtml

<ui:composition>
    <ace:column headerText="#{title}" sortBy="#{value}" filterBy="#{value}" filterMatchMode="contains">
        <c:choose>
            <!-- Editable -->
            <c:when test="${editable == 'true'}">
                <ace:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{value}"/>
                    </f:facet>
                    <f:facet name="input">
                        <h:inputText value="#{value}" />
                    </f:facet>
                </ace:cellEditor>
            </c:when>
            <!-- Not editable -->
            <c:otherwise>
                <h:outputText value="#{value}"/>
            </c:otherwise>
        </c:choose>
    </ace:column>
</ui:composition>

Class of produktdatenBean.lazyModel produktdatenBean.lazyModel 的 Class

public class LazyDataModelImpl<D> extends LazyDataModel<D>
{

    @Override
    public List<D> load(int first, int pageSize, SortCriteria[] sortCriteria, Map<String, String> filters)
    {
        ...
    }

}

The parameters 'first' and 'pageSize' are passed correctly and I can use them, to load my object from the database.参数“first”和“pageSize”已正确传递,我可以使用它们从数据库加载我的 object。 So everything working there.所以一切都在那里工作。 But now I'm trying to sort.但现在我正在尝试排序。

If I sort by the column ID, I get an object of SortCriteria in the array 'sortCriteria' (as expected).如果我按列 ID 排序,我会在数组“sortCriteria”中得到一个 object 的 SortCriteria(如预期的那样)。 Unfortunately it has set its propertyName to '#{value' instead of 'id' .不幸的是,它已将其 propertyName 设置为'#{value'而不是'id' So parameters inside the template don't get resolved when passed to the load() method.因此,当传递给 load() 方法时,模板内的参数不会得到解析。

If remove the templates and change my table to如果删除模板并将我的表更改为

Datatable with templates removed删除了模板的数据表

<ace:dataTable 
        id="produktdatenTabelle"
        value="#{produktdatenBean.lazyModel}"
        var="row"
        rows="20"
        paginator="true"
        paginatorPosition="bottom"
        paginatorAlwaysVisible="true"
        lazy="true">

    <ace:column headerText="ID" sortBy="#{row.id}" filterBy="#{row.id}" filterMatchMode="contains">
        <h:outputText value="#{row.id}"/>
    </ace:column>

    <ace:column headerText="Description" sortBy="#{row.description}" filterBy="#{row.description}" filterMatchMode="contains">
        <h:outputText value="#{row.description}"/>
    </ace:column>

</ace:dataTable>

everything works as expected (the SortCriteria has set propertyName to 'id' ).一切都按预期工作(SortCriteria 已将 propertyName 设置为'id' )。

So my question is: Can I use templates with a lazy loading ace:dataTable or is this not supposed to work?所以我的问题是:我可以使用带有延迟加载 ace:dataTable 的模板吗?或者这不应该起作用吗? If it is possible, what do I have to do to get the parameters passed correctly?如果可能的话,我该怎么做才能正确传递参数?

You need a Facelets tag file instead of a Facelets include file.您需要 Facelets 标记文件而不是 Facelets 包含文件。

The include file approach basically builds the include file only once during view build time and inserts the resulting JSF component tree in the place, which in turn get processed during view render time.包含文件方法基本上只在视图构建期间构建一次包含文件,并将生成的 JSF 组件树插入该位置,然后在视图渲染期间进行处理。 Because JSTL tags are executed during view build time, this means that all JSTL tags are already processed at that point.因为 JSTL 标记是在视图构建期间执行的,这意味着所有 JSTL 标记都已在此时处理。 However, the JSF datatable isn't processed during view build time, but only during view render time, so its var would always evaluate to null and hence the #{value} is always null in the include file.但是,JSF 数据表不会在视图构建期间处理,而只会在视图渲染期间处理,因此其var的计算结果始终为null ,因此包含文件中的#{value}始终为null

The tag file approach will process the tag file during view render time, so you're basically moving the JSTL job from view build time to view render time and then the var of the datatable will be available in the EL scope.标记文件方法将在视图渲染期间处理标记文件,因此您基本上是将 JSTL 作业从视图构建时间移动到视图渲染时间,然后数据表的var将在 EL scope 中可用。

You can keep the column.xhtml code untouched (I'd only put it in /WEB-INF so that endusers won't be able to request it standalone).您可以保持column.xhtml代码不变(我只将它放在/WEB-INF中,这样最终用户将无法单独请求它)。 You only need to create a .taglib.xml file, eg /WEB-INF/custom.taglib.xml :您只需要创建一个.taglib.xml文件,例如/WEB-INF/custom.taglib.xml

<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib 
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
    version="2.0"
>
    <namespace>http://example.com/custom</namespace>

    <tag>
        <tag-name>column</tag-name>
        <source>/WEB-INF/tags/column.xhtml</source>
    </tag>
</facelet-taglib>

If you register this as follows in /WEB-INF/web.xml ,如果您在/WEB-INF/web.xml中按如下方式注册,

<context-param>
    <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
    <param-value>/WEB-INF/custom.taglib.xml</param-value>
</context-param>

(the param value can refer multiple taglibs, you just need to semicolon-separate them) (参数值可以引用多个标签库,你只需要用分号分隔它们)

Then you'll be able to use it as follows,然后你就可以按如下方式使用它,

<html ... xmlns:my="http://example.com/custom">

...

<ace:dataTable 
    id="produktdatenTabelle"
        value="#{produktdatenBean.lazyModel}"
        var="row"
        rows="20"
        paginator="true"
        paginatorPosition="bottom"
        paginatorAlwaysVisible="true"
        lazy="true">

    <my:column title="ID" value="#{row.id}" />
    <my:column title="Description" value="#{row.description}" />
</ace:dataTable>

See also:也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM