0

私は、2 つのプロパティ court (CourtBean.java のオブジェクト) と courtAll (List オブジェクトには courtbean の配列リストが含まれています) を持つマネージド Bean (CourtUitility.java) を作成しました。私のコードは以下の通りです CourtUitility.java

@ManagedBean 
@RequestScoped
public class CourtUitility {

private CourtBean court =new CourtBean();
private List<CourtBean> courtAll = new ArrayList<CourtBean>();
/** Creates a new instance of CourtUitility */

public CourtUitility() {
    courtAll = new ArrayList<CourtBean>();
    int userID = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("USER_ID").toString());
    courtAll = CourtService.GenerateCourtList(userID);
}

public CourtBean getCourt() {
    return court;
}

public void setCourt(CourtBean court) {
    this.court = court;
}

public List<CourtBean> getCourtAll() {
    return courtAll;
}

public void setCourtAll(List<CourtBean> courtAll) {
    this.courtAll = courtAll;
}

public void save(ActionEvent actionEvent) {
     court.setUserID(Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("USER_ID").toString()));
    System.out.println("Court ID : " + court.getCourtID());
    System.out.println("User ID : " + court.getUserID());
    CourtService.AddCourt(court);
    court = new CourtBean();
    courtAll = CourtService.GenerateCourtList(Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("USER_ID").toString()));
    FacesMessage msg = new FacesMessage("Court Record Created", "");
    FacesContext.getCurrentInstance().addMessage(null, msg);
}
}

clientMaster.xhtml

<ui:composition template="/template/mainLayout.xhtml" >
        <ui:define name="pageContent">
 <h:form id="co">
                <p:growl life="5000" showDetail="true" showSummary="true" id="courtmessage" />
                <p:panel id="courtDetail" header="Court Details">
                    <p:messages id="panelMessage" showDetail="true" showSummary="false" autoUpdate="true" globalOnly="true" />

                    <h:panelGrid columns="4" styleClass="grid">
......
<p:commandButton id="addCourt" immediate="true" value="Add Court" actionListener="#{courtUitility.save}" update=":co,:cot" async="true" >
                        </p:commandButton>
                    </h:panelGrid>
                </p:panel>
            </h:form>
<ui:include id="abc" src="CourtEditDatatable.xhtml"/> 
        </ui:define>
    </ui:composition>

コマンドボタンから送信フォームに入ると、データベースですべてのデータが null になります。デバッグ後、フォームを送信すると、マネージド Bean コンストラクターが最初に呼び出され、すべてのプロパティが再初期化されることがわかりました。その後、アクションリスナーが呼び出されるため、データベースでnullになります。ビュースコープでも試しましたが、問題は同じままです。アクションリスナーが呼び出されている間にコンストラクターの呼び出しを停止する方法はありますか???

共有するもう1つのことは、同じプロジェクトで同じパターンのウィザードを使用してクライアントマスターを作成しました。正常に動作しています。レコードの保存中に問題が発生することはありません。魔法使いのせいですか??

4

1 に答える 1

3

アクションリスナーが呼び出されている間にコンストラクターの呼び出しを停止する方法はありますか???

Bean の構築を停止すると、Bean インスタンスがまったくなくなり、JSF は Bean でアクションを呼び出すことができなくなります。いいえ、これは意味がありません。

あなたの問題は他の場所で発生しています。フォームが不完全なのは残念ですが、少なくともimmediate="true"送信ボタンに が表示されます。「保存」ボタンでこれが必要な理由はわかりませんが、これは「キャンセル」ボタンでより一般的です。同じフォームのどの入力フィールドにもこの属性がない場合、それらはまったく処理されません。

ボタンから を削除するimmediate="true"と、JSF は送信された入力値を処理し、通常の方法でモデル値の更新フェーズ中に Bean に設定されます。

于 2012-06-08T14:40:31.833 に答える