简体   繁体   English

支持bean方法返回时如何在JSF中进行检测

[英]How to detect in JSF when the backing bean method returns

I need to detect when the backing bean method returns so that I can execute a javascript function. 我需要检测backing bean方法何时返回,以便执行javascript函数。 Alternatively, calling javascript code directly from within java source code would be helpful. 另外,直接从Java源代码中调用javascript代码将很有帮助。 Is there an example of how this is done? 有一个如何完成此操作的示例吗?

Here, when this command button is clicked, both the action and onclick execute simultaneously. 在此,单击此命令按钮时,动作和onclick会同时执行。 I need to execute the processAfterSave after the save method in the backing bean executes. 在执行支持bean中的save方法之后,我需要执行processAfterSave。

<h:commandButton id="saveButton" value="Save" type="submit" action="#{copyScript.save}" onclick="processAfterSave();" style="width: 75px;"/>

Just execute the JS code in the result page. 只需在结果页面中执行JS代码即可。 If the bean action returns to the same page, then you need to conditionally print the piece of JS code. 如果Bean操作返回到同一页面,则需要有条件地打印一段JS代码。

<f:verbatim rendered="#{bean.saved}">
    <script>processAfterSave();</script>
</f:verbatim>

In combination with 与结合

private boolean saved;

public void save() {
    // Business logic here.
    // ...
    saved = true;
}

public boolean isSaved() {
    return saved;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM