【发布时间】: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