私の現在のコード。
<h:form>
<h:panelGroup id="messagePanel" layout="block">
<h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
</h:panelGroup>
<h:panelGrid columns="2">
// some form input stuff here..
</h:panelGrid>
<h:commandButton class="register-btn" action="#{accountController.create}" value="#{bundle.Register}">
<f:ajax event="action" execute="@form" render="messagePanel"/>
</h:commandButton>
</h:form>
messagePanel は、検証エラーが表示される場所です。
create() メソッド
public String create() {
try {
getFacadeUser().create(currentUser);
FacesContext.getCurrentInstance().getExternalContext().redirect("/index.xhtml");
return null;
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
return null;
}
}
作成が成功した後に JavaScript を呼び出すことは可能ですか? 現在、私の作成フォームはポップアップモーダルです。ページにリダイレクトするのではなく、作成が成功した後にモーダルを非表示にするだけです。
私はJSF 2.1を使用しています