Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 2 使用jsf2的分页/排序机制_Jsf 2_Paging - Fatal编程技术网

Jsf 2 使用jsf2的分页/排序机制

Jsf 2 使用jsf2的分页/排序机制,jsf-2,paging,Jsf 2,Paging,我实现了一种排序机制来对表(从数据库加载)的结果进行排序。所有bean都是requestScope,每次用户对结果排序时,我都会向数据库进行新的查询。 我的问题是,它第一次运行良好,但如果单击两次,我的表就会重置。 在谷歌搜索之后,我发现我使用了与上面描述的相同的想法(thx Balusc;) 更详细地说,我创建了一个自定义组件,将其放入列的每个标题中: <composite:interface> <composite:attribute name="label" re

我实现了一种排序机制来对表(从数据库加载)的结果进行排序。所有bean都是requestScope,每次用户对结果排序时,我都会向数据库进行新的查询。 我的问题是,它第一次运行良好,但如果单击两次,我的表就会重置。 在谷歌搜索之后,我发现我使用了与上面描述的相同的想法(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}" />


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

你是否在使用(旧!;)博客中显示的
?在JSF2.0中,这应该不再是必需的了。只需将bean放在视图范围而不是请求范围中。但是,我不确定这是否能解决您的特定问题,因为代码不完整,所以我只是将其作为注释发布。让我知道它是否为您解决了问题。请求或查看范围,我有相同的行为:-/问题是,我第一次单击标题时,会调用排序方法,但第二次,我无法访问它。我编辑了我的第一篇文章:我删除了一些参数!!!代码现在是正确的。对不起,弄错了