【问题标题】:Iterated parameters with paginated datatable and ajax带有分页数据表和 ajax 的迭代参数
【发布时间】:2013-02-28 10:41:43
【问题描述】:

我正在尝试找到解决 datatable/ajax 问题的方法(简而言之):

<h:panelGroup layout="block" styleClass="ptl-body" id="toRender">
<h:dataTable value="#{flightMBean.flights}" var="f" id="flight_table" styleClass="table table-striped table-bordered">
    <h:column>
        <f:facet name="header">Airline</f:facet>
        <h:outputText value="#{f.airline.name}"/>
    </h:column>
    ...
    <h:column>
        <f:facet name="header">Status</f:facet>
        <span class="label label-success">Approved </span>
        <sec:authorize ifAnyGranted="ROLE_USER, ROLE_ADMIN">
            <h:form>
                <h:commandButton action="#{userMBean.observeFlight(f.id)}"
                                 styleClass="btn purple" value="Observe">
                    <f:ajax execute="@form" />
                </h:commandButton>
            </h:form>
        </sec:authorize>
    </h:column>
</h:dataTable>

分页器操作:

<h:form style="margin: 0 0 0 0">
<h:commandButton  styleClass="btn"
                  action="#{flightMBean.previous()}" 
                  rendered="#{flightMBean.paginator.hasPreviousPage}"
                  value="Prev">
    <f:ajax render=":toRender"/>
</h:commandButton>
<h:commandButton styleClass="btn" action="#{flightMBean.next()}" 
                 rendered="#{flightMBean.paginator.hasNextPage}"
                 value="Next">
    <f:ajax render=":toRender"/>
</h:commandButton>

对于数据表的第一个视图页面,一切似乎都在工作。当我单击“观察”时,具有良好 ID 的航班会进入数据库。当我单击“下一步”按钮时出现问题 - 数据表呈现新行,但每个 id 都与第一页上的相同。

例如,在第一页上,我有 fligh: from x to y at 20:00 with id=1 另一个 id=2,第二个页面使用 id=3 的第三个航班呈现。 如果我想观察第一次或第二次飞行,一切都很好! 如果我想观察第三个,id=1 的航班进入数据库。

PS。 如果我只放了 #{f.id} 而没有 form/commandButton/jsf 组件,一切看起来都很好......只是 jsf 组件重置了我的参数;/

【问题讨论】:

    标签: java ajax jsf jakarta-ee datatable


    【解决方案1】:

    如果支持 bean 是请求范围的,并且在(后)构造期间不保留完全相同的数据模型(&lt;h:dataTable value&gt; 后面的对象),则会发生这种情况。

    要么将 bean 放在视图范围内,要么在 bean 的(后)构造函数中编写逻辑,以保留与将带有表的表单呈现给最终用户时完全相同的数据模型。如果它取决于某些基于请求的条件,那么您可以使用&lt;f:param&gt; 来跨请求保留它们。

    另见:

    【讨论】:

    • 这是我一直在等待的答案!我将 bean 的范围从默认请求更改为查看范围,此时一切都在进行中:P
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-24
    • 1970-01-01
    • 2016-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-04
    相关资源
    最近更新 更多