简体   繁体   English

JSF中的ActionListener阶段

[英]ActionListener phases in JSF

HI, HI,

I have a doubt on calling the ActionListener method in the JSF beans. 我对在JSF bean中调用ActionListener方法有疑问。 For example every request or submission of JSF form is gone through the life cycle of six phases. 例如,JSF表单的每个请求或提交都经历了六个阶段的生命周期。 But, when we are triggering the particular event like action listener or value change listener, is there any lifecycle associated with that request? 但是,当我们触发特定事件(如动作侦听器或值更改侦听器)时,是否存在与该请求关联的生命周期?

Please clarify me. 请澄清我。

Any action listener is invoked during invoke action phase, before the real action method. 在实际操作方法之前的调用操作阶段期间调用任何操作侦听器。 Which action listener methods are to be invoked are determined based on the actionListener attribute of the UICommand component which is associated with the submit. 要调用哪些动作侦听器方法是根据与提交相关联的UICommand组件的actionListener属性确定的。

Any value change listener is invoked during validations phase (or apply request values phase when immediate="true" for the particular UIInput component) after a succesful conversion/validation of the submitted value and only when the submitted value differs from the initial value. 成功转换/验证提交的值之后,并且当提交的值与初始值不同时, 才会在验证阶段调用任何值更改侦听器(或在特定UIInput组件的immediate="true"时应用请求值阶段)。 Which value change listener methods are to be invoked are determined based on the valueChangeListener attribute of the UIInput components which are associated with the submit. 要调用哪些值更改侦听器方法是基于与提交关联的UIInput组件的valueChangeListener属性确定的。

And no, they do not have their own lifecycle. 不,他们没有自己的生命周期。 When they finish executing and return, it's still inside the same phase of the lifecycle. 当他们完成执行并返回时,它仍处于生命周期的同一阶段。 After invoking the valueChangeListener , JSF will continue with conversion/validation of the next UIInput component, or if there are none, then proceed to the next phase. 在调用valueChangeListener ,JSF将继续转换/验证下一个UIInput组件,或者如果没有,则继续下一阶段。 After invoking the actionListener , JSF will continue with the next actionListener or if there are none, invoke the real action method. 在调用actionListener ,JSF将继续使用下一个actionListener ,如果没有,则调用实际操作方法。


Update : after reading your comments again, I think that I now see your doubt about particularly the value change listener. 更新 :再次阅读您的评论后,我认为我现在看到您对特别是价值变化倾听者的怀疑。 You seem to think that it by default immediately fires a brand new request to the server side during the client side change event. 您似乎认为默认情况下,它会在客户端更改事件期间立即向服务器端发出一个全新的请求。 It does that not by default. 它是不是默认。 You can only achieve this by adding a little piece of JavaScript code which submits the entire HTML form during the change event of the HTML input field. 您只能通过添加一小段JavaScript代码来实现这一点,该代码在HTML输入字段的更改事件期间提交整个HTML表单。

onchange="this.form.submit()"

This part has nothing to do with JSF. 这部分与JSF无关。 It's a simple HTML attribute. 这是一个简单的HTML属性。 Open the page in webbrowser, rightclick and choose View Source . 在webbrowser中打开页面,右键单击并选择“ 查看源” You'll see that it's there. 你会看到它就在那里。 Disable JavaScript in your browser or remove it in JSF code and you'll see that it won't work anymore. 在浏览器中禁用JavaScript或在JSF代码中删除它,您将看到它将不再起作用。 You would need to press the submit button yourself to get it all to run. 你会需要按提交按钮自己把一切运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM