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