我有疑问如何更新同一页面上的其他复合组件。如果我输入客户 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>
组件案例.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)或者我应该尝试以某种方式在java代码中实现设计模式观察者?但是存在许多观察者(Customer,Case,...)的许多主题(MainPageController,SecondPageController,...)的问题。