[英]To pass JSF(primefaces) managed bean variable to javascript function
I have a JSF/primefaces managed bean.I am trying to pass managed bean variable to JavaScript function within the same managed bean but i am not successful. 我有一个JSF / primefaces托管bean。我试图将托管bean变量传递给同一托管bean中的JavaScript函数,但我不成功。 Can someone please help me in achieving this task.
有人可以帮我完成这项任务吗?
My managed bean code snippet 我的托管Bean代码段
reportName=report[0];
url="http://cvgapp42q/Reports/Pages/Report.aspx?ItemPath=%2fLPSR%2f"+reportName;
try {
RequestContext.getCurrentInstance().execute("window.open('#{repBean.url}')");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
url is the variable which i am trying to refer using the expression #{repBean.url} in the javascript function window.open() url是我尝试使用javascript函数window.open()中的表达式#{repBean.url}引用的变量。
Thanks in advance 提前致谢
just put your javascript code in a panel on your page: 只需将您的javascript代码放在页面上的面板中:
<h:panelGroup id="scriptPanel">
<script>
window.open('#{repBean.url}');
</script>
</h:panelGroup>
and update this panel after your ajax request, using update="scriptPanel"
on your related primefaces component. 并在您的Ajax请求之后使用相关的primefaces组件上的
update="scriptPanel"
更新此面板。
Use 采用
@ManagedProperty(value="#{repBean}")
RepBean repBean
and in your method 和你的方法
try {
RequestContext.getCurrentInstance().execute("window.open('"+repBean.getUrl()+"')");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.