2013-10-07 28 views
0

我想擴展p:inputTextArea的功能。新組件簡單的,看起來像:部分處理自定義組件ID的奇怪行爲

<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:composite="http://java.sun.com/jsf/composite" 
    xmlns:p="http://primefaces.org/ui" 
    xmlns:h = "http://java.sun.com/jsf/html"> 
<composite:interface> 
     ... 
    <composite:attribute name="maxlength" required="false" default="0"/> 
    <composite:attribute name="value" required="true"/> 
     ... 
</composite:interface> 
<composite:implementation> 
    <p:inputTextarea id="#{cc.clientId}" 
        value="#{cc.attrs.value}" 
        onkeyup="callJS('#{cc.clientId}', '#{cc.attrs.maxlength}')"/> <!-- This is why i extend p:inputTextarea --> 
</composite:implementation> 
</html> 

我用在p:TabView這個組件:

<h:form prependId="false"> 
     <p:tabView id="tabs"> 
      <p:tab id="tab1" title="text1"> 
       <h:outputLabel disabled="true" id="textarea" value="#{testBean.text}"/> 
      </p:tab> 
      <p:tab title="text2"> 
       <p:commandLink value="Show dialog" onclick="inputDilog.show();"/> 
       <p:dialog widgetVar="inputDilog" id="dialog"> 
        <!-- custom component --> 
        <practice:inputTextarea id="text" value="#{testBean.text}" maxlength="100"/> 

        <f:facet name="footer"> 
         <p:commandButton id="button" title="Save text" 
             update="textarea" 
             process="text" 
             oncomplete="inputDilog.hide();"/> 
        </f:facet> 
       </p:dialog> 
      </p:tab> 
     </p:tabView> 
    </h:form> 

testBeanPOJO

@ManagedBean(name = "testBean") 
@ViewScoped 
public class TestBean implements Serializable { 

    private String text; 

    public String getText() { 
     return text; 
    } 

    public void setText(String text) { 
     this.text = text; 
    } 
} 

當我p:commandButton [id=button]點擊我期待什麼成分與[id = textarea]將從組件[id = text]獲得價值。
但我正在從服務器

響應
<update id="tabs:textarea"><![CDATA[<label id="tabs:textarea"></label>]]></update> 

如果不是practice:inputTextareap:inputTextarea所有工作的期望。
如果practice:inputTextareap:tabView出來也按預期工作。

當自定義組件位於p:tabView時,爲什麼practice:inputTextarea的值不被處理?

回答

0

我把複合元件包裝成div。現在一切正常。

複合材料部件,現在看起來像

<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:composite="http://java.sun.com/jsf/composite" 
    xmlns:p="http://primefaces.org/ui" 
    xmlns:h = "http://java.sun.com/jsf/html"> 
<composite:interface> 
    ... 
<composite:attribute name="maxlength" required="false" default="0"/> 
<composite:attribute name="value" required="true"/> 
    ... 
</composite:interface> 
<composite:implementation> 
    <div id="#{cc.clientId}"> 
     <p:inputTextarea id="innerId" 
         value="#{cc.attrs.value}" 
         onkeyup="callJS('#{cc.clientId}:innerId', '#{cc.attrs.maxlength}')"/> 
    </div> 
</composite:implementation> 
</html>