javascript JSF 防止 commandLink 重新加载页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21163347/
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
JSF Prevent commandLink to reload page
提问by Cechinel
I need to prevent it because I'm losing the params from the page when the button is clicked.
我需要阻止它,因为单击按钮时我会丢失页面中的参数。
This is my code:
这是我的代码:
<h:commandLink styleClass="ui-btn ui-btn-c ui-icon-arrow-r ui-btn-icon-right" value="Continuar" action="#{metaWEB.btnProximo()}" />
I found some results here, like that How make commandButton not fully refresh page? How to use f:ajax?
我在这里找到了一些结果,比如如何使 commandButton 不完全刷新页面?如何使用 f:ajax?
But my action use messages from the page, so it need reload the form, but the page not.
但是我的操作使用来自页面的消息,所以它需要重新加载表单,但页面不需要。
I found this thread https://stackoverflow.com/questions/18868130/preventing-jsf-commandbutton-from-reloading-the-page/18868374#18868374
I think could be my solution, but I don't understand what he did :(
我认为可能是我的解决方案,但我不明白他做了什么:(
Thanks Advanced
感谢高级
回答by BalusC
Just make it an ajax (asynchronous) button instead of a regular (synchronous) button. It's a matter of nesting a <f:ajax>
inside the existing tag.
只需将其设为 ajax(异步)按钮而不是常规(同步)按钮即可。这是<f:ajax>
在现有标签内嵌套 a 的问题。
<h:commandLink ...>
<f:ajax execute="@form" render="@form" />
</h:commandLink>
The execute="@form"
tells JSF to process the entire form (all input components enclosed in the form the command component is sitting in). The render="@form"
tells JSF to update the entire form as ajax response (so if you display messages inside the very same form, they would be updated as well).
将execute="@form"
告诉JSF处理整个表格(封闭在命令部件被坐在形式的所有输入组件)。该render="@form"
告诉JSF更新整个形式Ajax响应(所以如果你非常相同的表单中显示的消息,他们将被更新)。
Don't forget to make sure that you return null
or void
from the button's action method, otherwise the view may still change as consequence of a non-null
/void
navigation outcome.
不要忘记确保您返回null
或void
从按钮的操作方法返回,否则视图可能仍会因非null
/void
导航结果而更改。
See also:
也可以看看:
回答by Sergeenho
Just remember to change the render="@none" to not reload the page...
请记住更改 render="@none" 以不重新加载页面...
<f:ajax execute="@form" render="@none" />