1

私はこのページを持っています:

      <h:head></h:head>
    <h:body>
        <h:form id="someForm">
            Form is here
        </h:form>
        <h:form>
            <a4j:commandButton id="editButton" value="editSomeString"
                            execute="@this"
                            action="#{testBean.edit('afterEdit')}"
                            oncomplete="#{rich:component('editPanel')}.show()"
                            render="editPanel"/>
            <rich:popupPanel modal="true" id="editPanel" autosized="true"
                          domElementAttachment="form">
                <f:facet name="controls">
                    <a4j:ajax event="show" oncomplete="alert('#{testBean.someString}')" />
                </f:facet>
                Changed value is          
                #{testBean.someString}
            </rich:popupPanel>
        </h:form>
    </h:body>

この Bean では:

@ViewScoped
@ManagedBean(name = "testBean")
public class TestBean implements Serializable {

public TestBean() {
    someString = "initValue";
}
private String someString;


public String getSomeString() {
    return someString;
}


public void setSomeString(String someString) {
    this.someString = someString;
}


public void edit(String value) {
   someString = value;
}

}

ポップアップのボタンをクリックすると、正しい値 (afterEdit) が表示され、アラート ボックスには古い値 (initValue) が表示されます。最初のフォーム (id=someForm) を削除するか、Bean スコープをセッションに変更すると、問題なく動作します (afterEdit 値がアラート ボックスに表示されます)。何が起こっているのですか?

私はjsfにこの依存関係を使用します:

      <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.1.1-b04</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.1.1-b04</version>
        <scope>compile</scope>
    </dependency>

richfaces 4.0.0.Final および GlassFish Server Open Source Edition 3.1.2 (ビルド 23) とともに

同じページの別のバリエーション (onhide および onshow メソッドを追加)

<h:head></h:head>
    <h:body>
        <h:form id="someForm">
            Form is here
        </h:form> 
        <h:form>
            <a4j:commandButton id="editButton" value="go"
                            execute="@this"
                            action="#{testBean.edit('afterEdit')}"
                            oncomplete="#{rich:component('editPanel')}.show()"
                            render="editPanel,y"/>
            <rich:popupPanel modal="true" id="editPanel" autosized="true"
                             styleClass="taskEditPanel" domElementAttachment="form" onhide="alert('from on hide #{testBean.someString}')" onshow="alert('from on show #{testBean.someString}')">
                <f:facet name="controls">
                    <a4j:ajax event="show" oncomplete="alert('show complete #{testBean.someString}')"  />
                    <a4j:ajax event="hide" oncomplete="alert('hide complete  #{testBean.someString}')"/>
                </f:facet>
                Changed value is           
                #{testBean.someString}
                 <a4j:commandButton id="exitButton" value="exit"
                            execute="@this"
                            oncomplete="#{rich:component('editPanel')}.hide()"
                            />
            </rich:popupPanel>
        </h:form> 
    </h:body>

ポップアップを開いて閉じようとすると、次のアラートが表示されます。

  1. 「ショーの後編集から」
  2. 「完全な initValue を表示」
  3. "from on hide afterEdit"
  4. 「完全な initValue を隠す」

a4j:ajax がポップアップのメソッド以外の場所から値を取得しているように見えますか? ViewStateの問題ですか?同じ ID で値が異なる 2 つの非表示の javax.faces.ViewState フィールドがあります。それらは全体像の状態を表しているのか、それとも含まれている形だけを表しているのか? ビュー全体でこれら 2 つのフィールドが同じ値を持つ必要がある場合、a4j:ajax が更新されていない最初のフォームからビューステートを見ている可能性がありますか? ビューステートの処理方法とそれが何を表しているかに関するリソースへのリンクは素晴らしいでしょう (ビューステートがここに当てはまらない場合でも)

4

1 に答える 1

1

a4j:region状態がサーバーに送信されないため、jsf は他のフォームを更新したくないため、同じフォームを使用して異なるフォームを分離することができます。使用するsessionScopeと、状態がサーバーに保存され、それが可能になりますが、実際の Web アプリには最適なソリューションではありません

于 2012-09-18T09:05:53.317 に答える