使用 <f:ajax> 调用 <h:commandLink> 操作方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5393500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Invoke <h:commandLink> action method using <f:ajax>
提问by martijnve
I have the following code:
我有以下代码:
<h:commandLink action="#{testBean.showSomething}">
Do Stuff
</h:commandLink>
wich 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:
做了我想要的(更改 testbean 的状态并重新加载页面,该页面将显示一组不同的 div。因为它们的“渲染”属性)现在我想使用 ajax 来完成这个,所以我这样做了:
<h:commandLink action="#{testBean.showSomething}">
<f:ajax event="click" render=":content" />
Do Stuff
</h:commandLink>
However this causes the showSomething method to not even be called. IMHO what i want to do is rather simple but i cant for the life of me figure out how to do it.
然而,这会导致 showSomething 方法甚至不被调用。恕我直言,我想做的很简单,但我一生都无法弄清楚如何去做。
回答by BalusC
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 UICommandcomponent.
您需要使用event="action"而不是event="click". 你甚至可以完全省略它。即<f:ajax>嵌套在UICommand组件中时正在侦听的默认事件。
<h:commandLink action="#{testBean.showSomething}">
<f:ajax render=":content" />
Do Stuff
</h:commandLink>

