Primefaces号码:日历,电话号码:阿贾克斯值未更新(一步延迟)电话号码、日历、号码、Primefaces

2023-09-11 22:29:07 作者:指尖韶华丶转瞬沧海已桑田

我要调用一个bean后,在点选择一个日期:日历。在我的设置我有一个 @Named @ViewScoped 豆,类 ObWith​​Date @实体与日期字段的 validFrom 的。

I want to call a bean after a date is selected in a p:calendar. In my setup I have a @Named @ViewScoped Bean, the class ObWithDate is a @Entity with a date field validFrom.

<h:form id="fUser">
  <p:dataTable id="dt" var="cum" value="#{myBean.listObWithDates}">
    <p:column>
      <p:calendar id="cValidFrom" value="#{cum.validFrom}">  
        <p:ajax event="dateSelect" listener="#{myBean.update(cum)}"
                update=":fUser:dt"/>  
      </p:calendar>  
    </p:column>
  </p:dataTable>
</h:form>

的好处是,该bean的方法更新(ObWith​​Date MYO)是我选择日期每次调用正确的对象。坏事是,​​ myO.validFrom 不具有正确的值。它总是落后一步的:

The good thing is, that the bean method update(ObWithDate myO) is called with the correct object each time I select a date. The bad thing is, that myO.validFrom does not have the correct value. It's always one step behind:

在现场用2012-01-01 初始化 在GUI更改为2012-01-05,bean方法调试到2012-01-01 在GUI更改为2012-01-15,bean方法调试到2012-01-05

这个问题让我发疯,我已经发现了几个问题没有正确更新值,也有一些关于号码:日历。他们中的大多数建议使用属性 selectListener =#{calendarBean.handleDateSelect} handleDateSelect(DateSelectEvent事件)方法。但我想打电话给我的方法,因为我想通过变量的当前实例。

This issue drives me crazy, I've found several issues with not correctly updated values and also some about p:calendar. Most of them suggest using the attribute selectListener="#{calendarBean.handleDateSelect}" with a handleDateSelect(DateSelectEvent event) method. But I want to call my method since I want to pass the current instance of the variable.

在Firebug的核实,正确更新值在POST请求发送 在我使用Primefaces 3.2和JBoss-7.1.1-最后 即使没有号码:dataTable中,只使用号码:日历的问题还是一样 的错误的调试输出的值可以被观察到的方法,对象更新(ObWith​​Date MYO),以及在相应的条目 myBean.listObWith​​Dates &LT;号码:阿贾克斯立即=真正的... /&GT; 并没有解决这个问题 Firebug verifies, that the correct updated values are transmitted in a POST request I'm using Primefaces 3.2 and JBoss-7.1.1-Final Even without the p:dataTable and only using p:calendar the issue is still the same. The wrong value of the debug output can be observed for the method-Object update(ObWithDate myO) as well for the corresponding entry in myBean.listObWithDates. <p:ajax immediate="true" .../> does not solve this issue.

更新 MattHandy帮了我很多,由此产生的问题的如何获得相应的列表项中的豆类方法中的AJ​​AX调用?的配制在后续 JSF号码:历号码:dataTable中:如何获得p的行:AJAX dateSelect事件

Update MattHandy helped me a lot, the resulting question How to get the corresponding list item in the ajax call inside the beans method? is formulated in the followup JSF p:calendar in p:dataTable: How to get the row of p:ajax dateSelect event.

推荐答案

这是最有可能的一个生命周期的问题。的制定者你的领域被称为的 的监听器执行之前。你不应该使用监听器来设置你的价值。

This is most likely a lifecycle issue. The setter for your field is called before your listener executes. You should not use the listener to set your value.

在你的听众的EL EX pression评估在呈现的 previous 的请求的响应阶段从而持有值落后一步。

The el expression on your listener is evaluated at render response phase of the previous request thus it holds the cum value "one step behind".

您应该从日历的日期值的二传手更新您的自定义对象。

You should update your custom object from the setter of the calendar's date value.