2014-10-28 113 views
1

我有一个JSF/primefaces托管bean。我试图在同一个托管bean中将托管bean变量传递给JavaScript函数,但是我不成功。有人可以帮助我完成这项任务。将JSF(primefaces)托管bean变量传递给javascript函数

我的托管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是我试图使用表达式#{repBean.url}在JavaScript功能window.open()

指可变

在此先感谢

回答

0

使用

@ManagedProperty(value="#{repBean}") 
RepBean repBean 

,并在你的方法

try { 
    RequestContext.getCurrentInstance().execute("window.open('"+repBean.getUrl()+"')"); 
} catch (Exception e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 
+0

,谢谢你的回复.repBean.getUrl()获取当前页面的url。但是我打开一个新的url http://cvgapp42q/Reports/Pages/Report.aspx .....如上所述这个问题。我只是想知道如何将包含url值的变量** url **传递给js函数,以便该值可检测并打开新的网页。 – rks 2014-10-28 13:56:54

+0

我不知道我是否真的明白你想要什么(这可能是因为我的英语不好)。如果你只想打开'url',你可以使用'RequestContext.getCurrentInstance()。execute(“window.open('”+ url +“')”); – drkunibar 2014-10-28 14:44:55

1

只要把你的JavaScript代码在面板页面上:

<h:panelGroup id="scriptPanel"> 
    <script> 
     window.open('#{repBean.url}'); 
    </script> 
</h:panelGroup> 

和你的Ajax请求后更新此面板上,您的相关primefaces组件使用update="scriptPanel"