[英]JSF: calling javascript code from Managed Bean not working when forcing page reload
我需要從JSF Managed Bean的方法執行JavaScript代碼,該方法基本上是單擊facelet(.xhtml文件)上的按鈕。 所有這些都可以通過使用PrimeFaces的RequestContext.execute(“ {js here}”)完美地實現,但是當通過使用ExternalContext添加一些“頁面重新加載”代碼行時,它將不再起作用(請參見下面的代碼)。 似乎“頁面重新加載”行阻止了JavaScript代碼的執行。 任何提示都歡迎!
public void myMethod() throws IllegalStateException, Exception {
RequestContext rc = RequestContext.getCurrentInstance();.
rc.execute("$('#myButton').click();");
try {
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.redirect(((HttpServletRequest) ec.getRequest()).getRequestURI());
} catch (IOException e) {
log.error("Error", e);
}
RequestContext用於當前請求,重定向是另一個請求。 它行不通。
嘗試做這樣的事情:
RequestContext rc = RequestContext.getCurrentInstance();
rc.execute("$('#myButton').click(); window.location = newURL;");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.