0

私の現在のコード。

<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を使用しています

4

2 に答える 2

0

<script>標準の JSF (読んでください: PrimeFaces や OmniFaces など、これを簡単にする方法を持つコンポーネント ライブラリやユーティリティ ライブラリはありません) では、要素を条件付きでレンダリングすることが最善の策です。

<h:panelGroup id="script">
    <h:outputScript rendered="#{not empty accountController.currentUser.id}">
        alert('User successfully created!');
    </h:outputScript>
</h:panelGroup>

で参照して<f:ajax ... render="script">ください。

于 2013-02-12T12:29:50.963 に答える
0

マネージド Bean でダイアログのコンポーネント バインディングを作成し、そのバインディングを使用して関数からダイアログを非表示にすることができます。コンポーネントバインディングを表すオブジェクトのタイプはフレームワーク固有であると思います(ただし、それらはすべておそらく UIComponent を拡張します)。そのため、完全なソリューションに使用している JSF 実装を指定する必要があります。たとえば、まさにこのユース ケースを ADF に実装しました。

これは ADF の例です。
<af:popup id="sample" binding="#{viewScope.myBean.myPopup}">

およびマネージドBeanで:
RichPopup myPopup;
...
public void onSave() {
//save user
myPopup.hide();
}

于 2013-02-11T12:48:49.063 に答える