JSF:在强制页面重新加载时从托管 Bean 调用 javascript 代码不起作用

JSF: calling javascript code from Managed Bean not working when forcing page reload

我需要从 JSF Managed Bean's method that is basically to click a button on a facelet (.xhtml file). All this works perfectly by using PrimeFaces' 执行 JavaScript 代码]RequestContext.execute("{js here}"),但是当使用 ExternalContext...[=18= 添加一些 'page reload' 代码行时它不再有效](请参阅下面的代码)。 'page reload' 行似乎阻止了 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;");