JSF f:ajax 监听器 vs commandButton 动作 [英] JSF f:ajax listener vs commandButton action

查看:24
本文介绍了JSF f:ajax 监听器 vs commandButton 动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇这两种执行ajax调用的方式有什么区别:

I'm curious what is the difference between these two ways of executing ajax calls:

<h:commandButton value="Submit" action="#{bean.action}">
   <f:ajax execute="@form" render="component"/>
</h:commandButton>

<h:commandButton value="Submit">
   <f:ajax listener="#{bean.action}" execute="@form" render="component"/>
</h:commandButton>

似乎人们更常使用第一种方式,但第二种方式似乎也能正常工作......

It appears that people use the first way more often, but the second seems to work just fine as well...

推荐答案

第一种方式允许通过返回 String 结果进行导航,第二种方式不允许.如果客户端禁用了 JS,第二种方式不会调用任何东西,而第一种方式 优雅降级.确实,第一种方式使用得更频繁.

The first way allows for navigation by returning a String outcome and the second not. The second way won't invoke anything if the client has JS disabled, while the first way gracefully degrades. Indeed, the first way is used more often.

第二种方式是组件中唯一没有 action 属性的方式,例如 等.

The second way is the only way in components which doesn't have an action attribute, such as <h:selectOneMenu> and so on.

这篇关于JSF f:ajax 监听器 vs commandButton 动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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