事件函数在Setter之前调用 [英] Event Function called before Setter

查看:94
本文介绍了事件函数在Setter之前调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下下拉列表,其中列出了几辆车,我有这样的列表,以便它将所选项目的值存储在backbean变量中,并触发一个事件,以便其他下拉列表根据此下拉控件的选定值填充如下:

I have the following dropdown which list couple of cars, I have it so that it stores the value of selected item in a backbean variable and an event is fired so other dropdowns would fill up according to the selected value of this dropdown control as below:

  <Td>
<h:selectOneMenu id="combocarList" 
    value="#{customerBean.selectedcar}"
    styleClass="comboStyle"
    valueChangeListener="#{customerBean.loadothercombos}"
    onchange="document.forms[0].submit()"
    >
    <f:selectItem
        itemLabel="-----------Select--------------"
        itemValue="None" />
    <f:selectItems value="#{customerBean.carsList}" />
</h:selectOneMenu>
 </Td>

问题是,当从上述下拉列表中选择一个项目时,在setter之前调用了loadothercombos事件,这会导致问题.

Problem is when an item selected from the above dropdown, the event loadothercombos is called before the setter which causes problems.

请注意,backbean客户定义为:

Note that the backbean customer is defined as:

 <managed-bean-name>customerBean</managed-bean-name>
    <managed-bean-class>com.theway.customer</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>

在调试中看到的行为是,当我从下拉列表中选择一个项目时:

The behaviour i see in debugging that when i select an item from dropdown:

1) Getter is called for selectedcar
2) Loadothercombos is called  <------- This is called by the event
3) Setter is called for selectedcar

在调用loadothercombos之前,我无法让它调用设置器.任何见识将不胜感激.谢谢

I cannot get it to call the setter before calling loadothercombos. Any insight would be appreciated. Thanks

推荐答案

问题是当从上述下拉菜单中选择一个项目时,该事件 在setter之前调用loadothercombos

Problem is when an item selected from the above dropdown, the event loadothercombos is called before the setter

是预期的JSF生命周期行为.仅在提交的值与初始值不同的情况下,在成功转换/验证提交的值之后,将在验证阶段调用valueChangeListener="#{customerBean.loadothercombos}".调用valueChangeListener之后,JSF将继续进行下一个UIInput的转换/验证,并且当JSF实现确定数据有效时,然后继续进行下一个Update Model Values Phase调用您的setter方法value="#{customerBean.selectedcar}"

Well, is the expected JSF life cycle behavior. Your valueChangeListener="#{customerBean.loadothercombos}" is invoked during validation phase after a succesful conversion/validation of the submitted value and only when the submitted value differs from the initial value. After invoking the valueChangeListener, JSF will continue with conversion/validation of the next UIInput and when JSF implementation determines that the data is valid, then proceed to the next Update Model Values Phase invoking your setter method value="#{customerBean.selectedcar}"

这篇关于事件函数在Setter之前调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆