调用 <h:commandLink>使用 &lt;f:ajax&gt; 的动作方法 [英] Invoke &lt;h:commandLink&gt; action method using &lt;f:ajax&gt;

查看:24
本文介绍了调用 <h:commandLink>使用 &lt;f:ajax&gt; 的动作方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

<h:commandLink action="#{testBean.showSomething}">
    Do Stuff
</h:commandLink>

它做我想要的(改变 testbean 的状态并重新加载页面,这将显示一组不同的 div.因为它们的渲染"属性)现在我想使用 ajax 来完成这个,所以我这样做了:

which does what I want (change the state of testbean and reload the page which will show a different set of divs. because of their "rendered" properties) Now I want to use ajax to accomplish this so I did this:

<h:commandLink action="#{testBean.showSomething}">
    <f:ajax event="click" render=":content" />
    Do Stuff
</h:commandLink>

然而,这会导致 showSomething 方法甚至不被调用.恕我直言,我想做的事情很简单,但我一生都无法弄清楚如何去做.

However this causes the showSomething method to not even be called. IMHO what I want to do is rather simple but I can't for the life of me figure out how to do it.

推荐答案

您需要使用 event="action" 而不是 event="click".你甚至可以完全省略它.这是 在嵌套在 UICommand 组件中时监听的默认事件.

You need to use event="action" instead of event="click". You could even omit it altogether. It's namely the default event the <f:ajax> is listening on when nested in an UICommand component.

<h:commandLink action="#{testBean.showSomething}">
    <f:ajax render=":content" />
    Do Stuff
</h:commandLink>

这篇关于调用 <h:commandLink>使用 &lt;f:ajax&gt; 的动作方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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