从服务器端启动JavaScript调用 [英] Initiating JavaScript call from server side
问题描述
我正在阅读这个,大约一半是从中调用JavaScript函数的一种策略服务器端。工作几乎完美,但我想阻止原始页面重新加载。尝试使用< a4j:commandLink>
执行此操作,但随后弹出页面根本没有显示。关于如何实现这一点的任何想法?
I was reading this and about halfway down is a tactic to call a JavaScript function from the server side. Works almost perfectly but I would like to prevent the original page from reloading. Tried to do this with an <a4j:commandLink>
but then the popup page wasn't appearing at all. Any ideas on how to achieve this?
推荐答案
在你发布正在运行的代码之前,你可能得不到具体答案为什么< a4j:commandLink />
失败
Until you post the code you're running, you might not get a specific answer why the <a4j:commandLink/>
is failing
然而,没有任何额外的库,执行客户端代码的一种黑客方法是使用 PartialViewContext
。该机制类似于教程推荐的机制,只是您不需要任何实用程序来实现相同的效果。
Without any additional libraries however, a hacky way to execute client-side code is to use the PartialViewContext
. The mechanism is similar to what that tutorial recommends, only that you don't need any utility to achieve the same effect.
String javaScriptText = "window.open('"+actionUrl+"', 'popupWindow', 'dependent=yes, menubar=no, toolbar=no');";
FacesContext cxt = FacesContext.getInstance();
PartialViewContext partialCtxt = ctxt.getPartialViewContext();
partialCtxt.getExecuteIds().add(javaScriptText);
这篇关于从服务器端启动JavaScript调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!