我需要根据'pickuphour'中选择的值更新'pickupdate'。
我的问题是,当调用更新侦听器时,侦听器方法中没有新选择的“pickuphour”值。
在转换器更新我的bean“pickuptime”值之前,似乎会调用侦听器。
(我在这里使用了DatePartConverter:Binding more than one input field to a backing bean property by using Java Server Faces?)
如何在侦听器方法之前或之后获取新选择的小时值?
<h:panelGroup>
<h:form id="pickuptime">
<p:selectOneMenu id="pickupdate" widgetVar="pickupdate" value="#{journeyCRUD.pickuptime}" immediate="true">
<f:selectItem itemLabel="Today" itemValue="#{journeyCRUD.dateList[0]}" noSelectionOption="true"/>
<f:selectItem itemLabel="Tomorrow" itemValue="#{journeyCRUD.dateList[1]}" />
<f:selectItems value="#{util:subList(journeyCRUD.dateList, 2, 30)}" var="date" itemValue="#{date}" itemLabel="#{util:formatDate(date, 'EEE dd MMM yyyy','EEE dd MMM')}"/>
<f:converter converterId="datePartConverter"/>
<f:attribute name="part" value="date"/>
<f:ajax execute="@this pickuphour pickupmin"/>
</p:selectOneMenu>
<p:selectOneMenu id="pickuphour" widgetVar="pickuphour" value="#{journeyCRUD.pickuptime}" immediate="true" >
<f:selectItems value="#{journeyCRUD.hourList}"/>
<f:converter converterId="datePartConverter"/>
<f:attribute name="part" value="hour"/>
<f:ajax event="change" listener="#{journeyCRUD.updatePickupDate}" execute="@this pickupmin" render="pickupdate" immediate="true"/>
</p:selectOneMenu>
<p:selectOneMenu id="pickupmin" widgetVar="pickupmin" value="#{journeyCRUD.pickuptime}" immediate="true">
<f:selectItems value="#{journeyCRUD.minuteList}"/>
<f:converter converterId="datePartConverter"/>
<f:attribute name="part" value="minutes"/>
</p:selectOneMenu>
</h:form>
</h:panelGroup>
答案 0 :(得分:1)
此转换器仅在设置了所有值后返回更新的模型值。如果你想继续使用这个转换器,最好的办法是直接从<f:ajax listener>
参数可用的组件中提取它。
public updatePickupDate(AjaxBehaviorEvent event) {
UIInput component = (UIInput) event.getComponent();
Object value = Component.getValue();
// ...
}