JSF comandButton execute action,然后以bean值为参数的js函数

JSF comandButton execute action, then js function with bean value as a parameter

我是从 JSF 开始的,所以它看起来很基础。 我有一个命令按钮,需要调用一个方法来计算 bean 值,我希望将新值作为参数传递给 JS 函数。 我的第一次尝试是(我的 js 函数中需要新的信息值):

    <h:commandButton  id="searchbtn" value="refresh" 
                     action="#{controller.computeBean}"
                     onclick="renderGraph('#{screenBean.info}');" >
        <f:ajax execute="@this" render="@this"   />
    </h:commandButton>

控制器调用成功。按钮被刷新,因此参数被更新。 但是 onClick 动作发生在控制器动作之前,因此 bean 还没有被渲染。所以我不得不在按钮上单击两次以获得所需的输出。 所以我使用了 primeface 的 oncomplete

    <p:commandButton  value="#refreshPF" 
                     action="#{controller.computeBean}"
                     oncomplete="renderGraph('#{screenBean.info}');"
                     update="@this">

    </p:commandButton>

但是现在在js函数中传递的bean并没有更新为新值。我知道调用该操作是因为我在执行控制器方法结束时打印了 bean 值。 我不确定我做错了什么,但我想它来自更新。 有人有一些可能有用的提示,我将非常感激。

使用的库: jsf 2.2.13 和 primeface 6.1

您可以从 Java 调用 JS 代码,这会在响应呈现时执行。查看:https://www.primefaces.org/showcase/ui/misc/requestContext.xhtml

在动作方法中Java你可以编码:

PrimeFaces.current().executeScript("alert('This onload script is added from backing bean.')");