2011-02-18 73 views
0

我需要检测backing bean方法何时返回,以便我可以执行javascript函数。或者,直接从Java源代码中调用JavaScript代码会很有帮助。有没有这样做的例子?当backing bean方法返回时如何在JSF中检测

在此,单击此命令按钮时,同时执行动作和onclick。执行后台bean中的save方法后,我需要执行processAfterSave。

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

回答

0

只需在结果页面中执行JS代码。如果bean操作返回到同一页面,那么你需要有条件地打印这段JS代码。

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

在结合

private boolean saved; 

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

public boolean isSaved() { 
    return saved; 
} 
相关问题