2010-05-27 102 views
1

我剛學習JSF 2並玩簡單的自定義組件。 設想一個支持AJAX的自定義組件有兩個inputText的領域:jsf 2.0複合組件 - 如何修改外部bean /屬性

... 
<h:body> 
    <composite:interface> 
    <composite:attribute name="domId" required="true" /> 
    <composite:attribute name="value" required="true" /> 
    </composite:interface> 
    <composite:implementation> 
    <h:inputText id="code" value="#{cc.attrs.value}"> 
    <f:valueChangeListener binding="#{domBean}" >  
    </f:valueChangeListener> 
     <f:ajax event="valueChange" execute="@this" 
     render="name"/> 
    </h:inputText> 

     <h:inputText id="name" value="#{domBean.name}" disabled="true"> 
    </h:inputText> 
    </composite:implementation> 
... 

該頁面使用的組件如下所示:

... 
<h:body> 
    <h:form> 
    <dom:domain domId="100" value="#{testCtrl.code}"/> 
    </h:form> 
</h:body> 
... 

在限定domBean類的有趣的方法是這樣的:

public void processValueChange(ValueChangeEvent event) 
     throws AbortProcessingException 
    { 
    String code = (String) event.getNewValue(); 
    UIInput input= (UIInput) event.getSource(); 
    name = resolveCode(code); //some magic transformation 
    if (name != null) 
     input.setValue(code); //just want to set the "entered"/"validated" text 
    } 

我期望input.setValue(代碼)將設置的inputText值,這是延遲表達式「#{cc.attrs。值}「,它通過」父「頁面鏈接到#{testCtrl.code}。 不幸的是,testCtrl.code從不填充輸入的值。

我做錯了什麼?

謝謝!

回答