使用jsf2的分页/排序机制

时间:2012-03-22 18:57:51

标签: jsf-2 paging

我实现了一种排序机制来对表的结果进行排序(从数据库加载)。所有bean都是requestScoped,每次用户对结果进行排序时,我都会对db进行新的查询。 我的问题是它第一次运行良好,但如果我点击两次,我的表将被重置。 谷歌搜索后,我发现我使用了同样的想法here(thx Balusc;))。

更详细地说,我创建了一个自定义组件来放入列的每个标题:

<composite:interface>
    <composite:attribute name="label" required="true" shortDescription="The label of the link"/>
    <composite:attribute name="action" required="true" shortDescription="The action for sorting"/>
    <composite:attribute name="columnName" required="true" shortDescription="The identifier of the column"/>
    <composite:attribute name="update" required="true" shortDescription="The id of element to update"/>
    <composite:attribute name="sortColumn" required="true" shortDescription="The column which we want sort"/>
    <composite:attribute name="sortOrder" required="true" shortDescription="The order of sort"/>
</composite:interface>
<composite:implementation>
<h:panelGroup
    rendered="#{cc.attrs.sortColumn!=cc.attrs.columnName}">
    <p:commandLink action="#{cc.attrs.action}"
        update="#{cc.attrs.update}"
        value="#{cc.attrs.label}"
        styleClass="sortable">
        <f:param name="sortOrder" value="ASCENDING" />
        <f:param name="sortColumn" value="#{cc.attrs.columnName}" />
    </p:commandLink>

</h:panelGroup>
<h:panelGroup
    rendered="#{cc.attrs.sortColumn==cc.attrs.columnName and cc.attrs.sortOrder=='DESCENDING'}">
    <p:commandLink action="#{cc.attrs.action}"
        update="#{cc.attrs.update}"
        value="#{cc.attrs.label}"
        styleClass="desc">
        <f:param name="sortOrder" value="ASCENDING" />
        <f:param name="sortColumn" value="#{cc.attrs.columnName}" />
    </p:commandLink>
</h:panelGroup>
<h:panelGroup
    rendered="#{cc.attrs.sortColumn==cc.attrs.columnName and cc.attrs.sortOrder=='ASCENDING'}">
    <p:commandLink action="#{cc.attrs.action}"
        update="#{cc.attrs.update}"
        value="#{cc.attrs.label}"
        styleClass="asc">
        <f:param name="sortOrder" value="DESCENDING" />
        <f:param name="sortColumn" value="#{cc.attrs.columnName}" />
    </p:commandLink>
</h:panelGroup>
</composite:implementation>

我以jsf页面的形式定义了两个隐藏字段:

<h:inputHidden value="#{myBean.sortOrder}" />
<h:inputHidden value="#{myBean.sortColumn}" />

如果有人可以解释我错在哪里?

0 个答案:

没有答案