在我的设置我有一个 @Named
豆,类 ObWithDate
是 @Entity
与日期字段的 validFrom 的。这个类的对象是在名单,其中,ObWithDate>
的bean。我想更新 ObWithDate
立即如果用户更改了日期。该号码:dataTable中
因而呈现出几个号码:日历
部分:
In my setup I have a @Named
Bean, the class ObWithDate
is a @Entity
with a date field validFrom. Objects of this class are in a List<ObWithDate>
of the bean. I want to update the ObWithDate
immediately if a user changes a date. The p:dataTable
thus is showing several p:calendar
components:
<h:form id="fUser">
<p:dataTable id="dt" var="i" value="#{myBean.list}">
<p:column>
<p:calendar id="cValidFrom" value="#{i.validFrom}">
<p:ajax event="dateSelect" listener="#{myBean.up}" update=":fUser:dt"/>
</p:calendar>
</p:column>
</p:dataTable>
</h:form>
bean的code:
The code of the bean:
public void up(DateSelectEvent event)
{
logger.info("DateSelectEvent "+event.getDate());
// How to get the corresponding ObWithDate?
}
这是 Primefaces p的后续问题:日历,电话号码:阿贾克斯值未更新(一步延迟)但现在瞄准具体问题:?如何获得在豆类方法中的Ajax调用相应的项目的
This is a subsequent question of Primefaces p:calendar with p:ajax value not updated (one step delay) but now targeting the concrete issue: How to get the corresponding list item in the ajax call inside the beans method?
您可以解决#{我}
编程(可怕的变量的方式名称)。
You could resolve #{i}
(terrible variable name by the way) programmatically.
FacesContext context = FacesContext.getCurrentInstance();
ObWithDate obWithDate = (ObWithDate) context.getApplication().evaluateExpressionGet(context, "#{i}", ObWithDate.class);
// ...
另一种方法是使用的DataModel
作为&LT值,P:dataTable的&GT;
这样就可以使用的DataModel#getRowData()
。
An alternative is to use DataModel
as value of the <p:dataTable>
so that you can use DataModel#getRowData()
.
private transient DataModel<ObWithDate> model;
private DataModel<ObWithDate> getModel() {
if (model == null) {
model = new ListDataModel<ObWithDate>(list);
}
return model;
}
这样就可以如下得到它在侦听器方法
so that you can get it in the listener method as follows
ObWithDate obWithDate = model.getRowData();
// ...