1

複合コンポーネント (jsf) への ActionListener の委任に関する具体的な質問があります。個人ユーザーデータ (属性「ユーザー」) を表示 (参照) および編集するための複合コンポーネントを作成しました。

    <body>
        <co:interface>
            <co:attribute name="editAction"     required="false"  targets="edit"   method-signature="java.lang.String f()"/>
            <co:attribute name="saveAction"     required="false"  targets="save"   method-signature="java.lang.String f()"/>
            <co:attribute name="cancelAction"   required="false"  targets="cancel" method-signature="java.lang.String f()"/>
            <co:attribute name="isBrowseModus"  required="true"/>
            <co:attribute name="user"           required="true"/>
            <co:attribute name="isDeveloper"    required="true"/>
            <co:actionSource name="edit"/>
            <co:actionSource name="save"/>
            <co:actionSource name="cancel"/>
        </co:interface>
............
        <p:inplace id="inpLand" editor="true" 
            toggleable="#{not cc.attrs.isBrowseModus}" 
            style="#{cc.attrs.isBrowseModus ? 'color: black' : 'color: blue'}">  
                <p:inputText value="#{cc.attrs.user.land}" label="text"/>  
        </p:inplace>  
...........
       <c:if test="#{cc.attrs.isBrowseModus}">
         <h:commandButton id="edit" value="Edit"/>
       </c:if>
........

実際には、この複合コンポーネントはmyData.xhtmlを呼び出すビューによって呼び出されます。

        <ui:define name="center">
            <h3>MyData Developer </h3>
            <h4>Welcomne</h4>
            <h:form id="dataForm">  
                <mc:UserData user="#{dataBean.user}" isDeveloper="#{dataBean.developer}" isBrowseModus="#{dataBean.browseModus}" cancelAction="#{dataBean.cancel}" 
saveAction="#{dataBean.save}" editAction="#{dataBean.edit}">
                    <f:actionListener for="edit" binding="#{dataBean.editActionListener}"/>
                </mc:UserData>   
            </h:form>  
        </ui:define>
    </ui:composition>

複合コンポーネント内には (id = edit) があり、配信された actionListener (myData 内の f:actionListener を参照) をこの commandButton (id = edit) にバインドする必要があります。これは、さまざまなフォーラムの議論といくつかのドキュメントを読んだ後の私の理解です。

残念ながら、Edit-Button をクリックしても editActionListener メソッドが起動されません。その理由はわかりません。確かに、このeditActionListenerメソッドは managedBean "dataBean" (myData.java) 内に存在します。

public void editActionListener(ActionEvent ae) {
    browseModus = false;
    FacesContext.getCurrentInstance().renderResponse();
}    

私の目的は何ですか:その複合コンポーネント内で、ユーザーは「編集」ボタンをクリックしてユーザーデータを変更できます。PRIMEFACES の inplace タグを使用することを好みます。編集ボタンをクリックすると、変更可能なすべてのフィールドが青色で表示されます。

私の質問:

  1. 境界付きの editActionListener メソッドが起動されない理由を誰か説明してもらえますか?
  2. 一般に、これは「isBrowseModus」属性を設定する正しい方法ですか (編集ボタンをクリックした後に false にします)? または、この結果を達成するためのより便利な方法はありますか?
  3. 私はプライムフェイスを使用しており、最初に p:commandButton を使用しようとしましたが、残念ながら機能しません。p:commandButton の使用中に、編集ボタンをクリックした後に例外が発生しました。JSF が managedBean 内で editActionListener メソッドを見つけられませんでした (PropertyNotFoundException)?!?!?

どんな助けでも感謝します。よろしくお願いします。よろしく、ボードー

4

1 に答える 1

2

タグのドキュメントによると、はメソッド式ではなく、インターフェイスを<f:actionListener binding>実装する具体的なインスタンスを参照する必要があります。ActionListener

ActionListener結局のところ、必要なアクション リスナー メソッドを呼び出す getter を介してインターフェースの具体的な実装を提供することで、問題を解決できます。

private ActionListener editActionListener = new ActionListener() {
    @Override
    public void processAction(ActionEvent event) throws AbortProcessingException {
        DataBean.this.editActionListener(event);
    }
};

public ActionListener getEditActionListener() {
    return editActionListener;
}

public void editActionListener(ActionEvent event) {
    browseModus = false;
    FacesContext.getCurrentInstance().renderResponse();
}

ただし、これは不器用であり、おそらく間違った方向に解決策を探していることを示しています。より簡単な方法は、<cc:attribute targets="edit">代わりに使用することです。

<cc:interface>
    ...
    <cc:attribute name="actionListener" targets="edit" />
</cc:interface>

として使用されます

<mc:UserData ... actionListener="#{dataBean.editActionListener}" />
于 2013-02-25T17:18:24.870 に答える