【问题标题】:Passing a converter to a composite component将转换器传递给复合组件
【发布时间】:2017-03-06 04:44:39
【问题描述】:

经过一些实验和阅读,我找到了与How to reference component inside a composite component when using a converter相同的解决方案

但问题是我有两个用于值持有者的 ID,根据文档,我可以使用 id1,id2 作为目标,但这不起作用。

这是我的复合组件:

<cc:interface>
    <cc:attribute name="id" required="true"/>
    <cc:attribute name="value" required="true"/>
    <cc:attribute name="editable" required="true"/>
    <cc:editableValueHolder name="element" targets="input,output"/>
</cc:interface>
<cc:implementation>
    <h:inputText value="#{cc.attrs.value}" id="input" rendered="#{cc.attrs.editable}"/>
    <h:outputText value="#{cc.attrs.value}" id="output" rendered="#{not cc.attrs.editable}"/>
</cc:implementation>

这就是我打算使用 CC 的方式:

<r:inputText editable="#{registrationBean.editable}" id="dateOfBirth"
             value="#{registrationBean.dateOfBirth}">
    <f:convertDateTime pattern="dd-MM-yyyy" type="date" for="element" />
</r:inputText>

我最初尝试通过 insertChildren 和 facet 插入转换器,但没有成功。

【问题讨论】:

    标签: jsf jsf-2.2 composite-component


    【解决方案1】:

    target 需要空格而不是逗号分隔

    如果存在,这必须是空格(不是制表符)分隔的客户端列表 内部组件的 ids(相对于顶级组件) 部分。空格用作分隔符 与 XML 中的 IDREFS 和 NMTOKENS 数据类型兼容 架构。

    JSF2.2 docs

    【讨论】:

    • 我也试过空格。事实上我在这里把 sn-p 改成了逗号,因为原来的 sn-p 有空格。
    • 这可能与我的复合组件/调用站点中的注释代码行有关吗?我删除了一些注释代码,突然它似乎正在工作。我还没有安全感,但是哦,好吧......
    猜你喜欢
    • 1970-01-01
    • 2020-06-17
    • 2011-06-02
    • 2012-03-01
    • 1970-01-01
    • 2018-11-16
    • 2014-02-19
    • 2018-06-05
    • 1970-01-01
    相关资源
    最近更新 更多