简体   繁体   中英

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. Alternatively, calling javascript code directly from within java source code would be helpful. Is there an example of how this is done?

Here, when this command button is clicked, both the action and onclick execute simultaneously. I need to execute the processAfterSave after the save method in the backing bean executes.

<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. If the bean action returns to the same page, then you need to conditionally print the piece of JS code.

<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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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