我有問題,我如何更新在同一頁上的其他複合組件。如果我輸入客戶ID並點擊「搜索」按鈕,客戶應在數據庫中搜索,如果存在,則系統繼續基於客戶ID搜索案例。反之亦然。JSF複合組件的每個其他更新
對於這個例子,假定關係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)或者我應該嘗試以某種方式在java代碼中實現設計模式Observer?但是有許多觀察者(Customer,Case,...)存在許多主題(MainPageController,SecondPageController,...)。
好的,我打包組件的情況下: ... h:panelGroup>。但是,您的意思是「將該ID作爲搜索並更新屬性」和「在命令按鈕中使用該屬性」? –
Ziletka
2012-04-19 16:46:55
對於遲到的回覆感到抱歉。我在休假。首先面板需要在一個表格內。接下來,爲您的組件創建一個新參數,該參數用於獲取表示要更新的項目的字符串。將該字符串饋送到命令按鈕的更新屬性中。 – mosgjig 2012-04-19 23:49:09
我還在戰鬥。但另一個問題:standart是否具有屬性「update」?或者我必須使用例如PrimeFaces commandButton? –
Ziletka
2012-04-20 16:13:35