如何使用OmniFaces Ajax.updateColumn()或Ajax.updateRow()通过电话号码:AJAX [英] How to use OmniFaces Ajax.updateColumn() or Ajax.updateRow() via p:ajax
问题描述
我试图用OmniFaces 1.3(快照)的Ajax工具的Ajax.updateColumn()方法。更具体地讲,我要替换使用号码:AJAX更新=:pageContentPanel,这是一个H:panelGroup中(或号码:outputPanel),其中包含以下XHTML,通过使用Ajax.updateColumn的(表1)。
I am attempting to use the Ajax.updateColumn() method of the OmniFaces 1.3 (SNAPSHOT) Ajax utility. More specifically, I want to replace the use p:ajax update=":pageContentPanel", which is an h:panelGroup (or p:outputPanel) which contains the following xhtml, with the use of Ajax.updateColumn(table, 1).
<h:dataTable id="dt_tripDates" style="width: 200px !important;"
var="tripDate" value="#{pf_ordersController.tripDates}">
<p:column style="text-align: right !important;">
<h:outputText id="rowNumber" value="#{tripDate.rowNumber}" />
</p:column>
<p:column style="text-align: center !important;">
<p:calendar id="tripDate" value="#{tripDate.tripDate}"
size="16" label="Trip Date"
pattern="MM/dd/yyyy" navigator="true"
onchange="changeOthersOnDateChange(this);">
<p:ajax partialSubmit="false" event="dateSelect"
listener="#{pf_ordersController.tripDateSelectedOnAddUsingTemplate}"
update=":pageContentPanel"/>
<f:convertDateTime pattern="MM/dd/yyyy" />
</p:calendar>
</p:column>
</h:dataTable>
在豆,我有以下的,这是由p引用:阿贾克斯监听=...
In the bean, I have the following, which is referenced by p:ajax listener="...":
public void tripDateSelectedOnAddUsingTemplate(DateSelectEvent event) {
DateTime dt, today = DateTime.now(),
tripDateTime = new DateTime(event.getDate());
String clientId = event.getComponent().getClientId();
Integer pos = clientId.indexOf(":tripDate") - 1,
rowNumber = Integer.valueOf(clientId.substring(clientId.lastIndexOf(":", pos) + 1, pos + 1));
/*
* clientId = orderAddUsingTemplateForm:dt_tripDates:0:tripDate
* id = tripDate
*/
/*
* if tripDates in the list, that follow the argument tripDate in the list,
* have today's Date, then set them to the argument
*/
for (int i = rowNumber; i < nbrOfTripDates; i++) {
tripDates.get(i).setTripDate(tripDateTime.toDate());
}
// OmniFaces Ajax utility to update UIData columns
Ajax.updateColumn(tripDatesDataTable, 1);
}
在尝试使用Ajax.updateColumn(),我补充说:HtmlDataTable tripDatesDataTable作为一个属性到bean。
While attempting to use Ajax.updateColumn(), I added "HtmlDataTable tripDatesDataTable" as an attribute to the bean.
这个bean是JSF @SessionScoped托管bean。请让我知道如何()当p我可以打电话Ajax.updateColumn:阿贾克斯(属于号码:日历在XHTML以上)执行。谢谢你。
The bean is JSF @SessionScoped managed bean. Please let me know how I can call Ajax.updateColumn() when p:ajax (belonging to p:calendar in xhtml above) is executed. Thanks.
推荐答案
关键的一点是,你得有一个句柄的 UIData code>
组件以某种方式,让您可以将其传递给阿贾克斯#updateColumn()
。在特定的情况下,最简单的办法是让它通过 event.getComponent()
与<帮助href="http://omnifaces.org/docs/javadoc/current/org/omnifaces/util/Components.html#getClosestParent%28javax.faces.component.UIComponent,%20java.lang.Class%29"相对=nofollow> 组件#getClosestParent()
。
The key point is that you've got to have a handle to the UIData
component somehow so that you can pass it to Ajax#updateColumn()
. In your particular case, easiest way would be to get it by event.getComponent()
with help of Components#getClosestParent()
.
UIData tripDatesDataTable = Components.getClosestParent(event.getComponent(), UIData.class);
// ...
Ajax.updateColumn(tripDatesDataTable, 1);
请注意,你也可以只得到了行号,而不需要打破客户端ID这种方式。
Note that you can also just get the row number this way without the need to break down the client ID.
int rowNumber = tripDatesDataTable.getRowIndex();
这篇关于如何使用OmniFaces Ajax.updateColumn()或Ajax.updateRow()通过电话号码:AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!