JSF号码:历号码:dataTable中:如何获得p的行:AJAX dateSelect事件号码、如何获得、事件、dateSelect

2023-09-10 15:46:19 作者:念你成狂

在我的设置我有一个 @Named 豆,类 ObWith​​Date @Entity 与日期字段的 validFrom 的。这个类的对象是在名单,其中,ObWith​​Date> 的bean。我想更新 ObWith​​Date 立即如果用户更改了日期。该号码: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();
// ...

参见:

How我可以将参数传递到一个commandLink一个DataTable里面?

See also:

How can I pass a parameter to a commandLink inside a datatable?