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;
}
精彩评论