what is differences between action and actionlistener in JSF components?

本文探讨了JavaServer Faces (JSF) 中的Action与Action Listener的区别与应用场景。Action方法通常用于按钮或链接点击后的业务逻辑处理,并可能根据执行结果进行页面导航;而Action Listener则用于执行一些不需要导航的操作,如响应复选框点击改变页面元素的显示状态。

Following refer to  the Faces event model.

Basically the "action" attribute refers to an action method which returns a String from which the Faces navigation model can use to decide whether or not a navigation is necessary based on the value of the string.

typically one uses an action method to execute some code after a button or link is clicked and then possibly navigate based on the outcome of executed code.

An actionlistener method compared to an action method does not return a String. Instead it returns void. It is basically identical to the action method but instead it just executes the code after an action event (button click or link click) but a navigation is not needed.

A good example of actionlistener could be in response to clicking on a checkbox and having the actionlistener code behind it change a visual attribute of a page such as render a component that was not rendered before..

Chapter 8 has exactly this example where I show how you can have a checkbox when clicked render an additional field in an input form.

So.  we just need to remember :

1.

    action:MethodExpression representing the application action to invoke when this component is activated by
 the user. The expression must evaluate to a public method that takes no parameters, and returns an
 Object (the toString() of which is called to derive the logical outcome) which is passed to the
 NavigationHandler for this application.

     actionlistener .MethodExpression representing an action listener method that will be notified when this component
 is activated by the user. The expression must evaluate to a public method that takes an
 ActionEvent parameter, with a return type of void.

2.singel page ,and it refresh itself  and don't direct or skip to next page , using actionlistener  better .

  direct or skip ,keep using action first .

3.
action : No paramters ,have return values

actionlistener :ActionEvent parameter, No return value (void) , can't navigation-rule

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值