同じページにある他の複合コンポーネントを更新する方法について質問があります。顧客 ID を入力して [検索] ボタンをクリックすると、顧客がデータベースで検索され、存在する場合、システムは顧客 ID に基づいてケースの検索を続行します。およびその逆。
この例では、関係 Customer:Case が 1:1 であると仮定します。
main_page.xhtml
<h:body>
<ui:composition template="/WEB-INF/template/layout.xhtml">
<ui:define name="content">
<custom:component_customer
customerId="#{mainPageController.customer.id}"
searchCustomer="#{mainPageController.searchCustomer}"
/>
<custom:component_case
caseaseId="#{mainPageController.case.caseId}"
searchCase="#{mainPageController.searchCase}"
/>
</ui:define>
</ui:composition>
</h:body>
component_customer.xhtml
<composite:interface>
<composite:attribute name="customerId" type="java.lang.Long"/>
<composite:attribute name="searchCustomer" method-signature="void searchCustomer()"/>
</composite:interface>
<composite:implementation>
<h:form>
<h:inputText id="id" value="#{cc.attrs.customerId}"/>
<h:commandButton value="Search" action="#{cc.attrs.searchCustomer}"/>
</h:form>
</composite:implementation>
component_case.xhtml
<composite:interface>
<composite:attribute name="caseId" type="java.lang.Long"/>
<composite:attribute name="searchCase" method-signature="void searchCase()"/>
</composite:interface>
<composite:implementation>
<h:form>
<h:inputText id="id" value="#{cc.attrs.caseId}"/>
<h:commandButton value="Search" action="#{cc.attrs.searchCase}"/>
</h:form>
</composite:implementation>
MainPageController.java
@ManagedBean
@ViewScoped
public class MainPageController {
@EJB
private CaseLogic caseLogic;
@EJB
private CustomerLogic customerLogic;
private Customer customer = new Customer();
private Case case = new Case();
// getter & setters
public void searchCustomer() {
}
public void searchCase() {
}
1)そのための一般的な「JSF」ソリューションはありますか?
2)または、どうにかして設計パターンObserverをJavaコードで実装してみるべきですか? しかし、多数のオブザーバー (Customer、Case など) に対して多数のサブジェクト (MainPageController、SecondPageController など) が存在するという問題があります。