问题
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>
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);
}
While attempting to use Ajax.updateColumn(), I added "HtmlDataTable tripDatesDataTable" as an attribute to the bean.
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.
回答1:
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);
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();
来源:https://stackoverflow.com/questions/13091742/how-to-use-omnifaces-ajax-updatecolumn-or-ajax-updaterow-via-pajax