2014-10-28 92 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"