本文介绍了如何从服务器端执行javascript方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在primefaces中,有一个RequestContext类,它增加了从服务器端调用javascript方法的功能:
in primefaces there's the RequestContext class which add the ability to invoke javascript method from server side :
RequestContext context = RequestContext.getCurrentInstance();
//execute javascript oncomplete
context.execute("PrimeFaces.info('Hello from the Backing Bean');");
我想知道是否可以在不使用撇号的情况下用jsf 2完成该操作,请告知.
i was wondering if it's possible to accomplish that with jsf 2 without using primefaces, please advise.
推荐答案
最简单但也是最hackest的方法是设置一个表示<h:outputScript>
内容的属性,并通过将其客户端ID添加到PartialViewContext#getRenderIds()
.
The easiest but also hackiest way would be to set a property which represents the content of a <h:outputScript>
and ajax-update it by adding its client ID to PartialViewContext#getRenderIds()
.
所以,给定一个
<h:panelGroup id="script"><h:outputScript>#{bean.script}</h:outputScript></h:panelGroup>
您可以使用ajax更新它
you can ajax-update it with
script = "alert('peek-a-boo')";
FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add("script");
这篇关于如何从服务器端执行javascript方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!