0

我想扩展p:inputTextArea. 新组件很简单,看起来像:

<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:inputTextarea编写p:inputTextarea所有工作。
并且如果practice:inputTextareap:tabView按预期工作。

practice:inputTextarea当自定义组件位于时,为什么不处理的值p:tabView

4

1 回答 1

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>
于 2013-10-08T15:00:17.247 回答