使用转换器时如何在复合组件内部引用组件 [英] How to reference component inside a composite component when using a converter

查看:82
本文介绍了使用转换器时如何在复合组件内部引用组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复合组件,主要由selectManyCheckbox组件组成.由于应该以通用方式进行设计,因此我使用

I have a composite component that mainly consists of a selectManyCheckbox component. As it should be designed in a generic way I pass in selectItems, ajax handling etc. from the calling level using

<composite:insertChildren/>

这对于大多数东西来说效果很好.现在,我需要将此复合组件与转换器一起使用.由于并非一直都需要转换器(一种Omnifaces的ListConverter)(有时我想让支持选择项的具体实体具有价值绑定,有时我不需要),所以我想通过它作为前面提到的部分(例如selectItems,ajax事件处理).

This works quite well for most of the stuff. Now I need to use this composite component with a converter. As the converter (a kind of Omnifaces' ListConverter) is not needed all the time (sometimes I want to have the value-binding of concrete entities that back the select items, sometimes I don't), I'd like to pass it in as the parts mentioned before (e.g. selectItems, ajax event handling).

鉴于此,有必要使用转换器标记的'for'属性引用复合组件内部的组件.至少这是我的理解.

Given this it is necessary to use the converter tag's 'for' attribute to reference the component inside the composite component. At least that is what I understand.

不幸的是,我不知道应该使用什么值.我是否必须包括复合组件的名称(命名容器)?我必须使用clientId吗?我尝试了很多组合,但尚未调用转换器.一旦将converter标记放入复合组件定义中,它就会起作用.

Unfortunately I have no idea what value should be used. Do I have to include the name of the composite component (naming container)? Do I have to use the clientId? I have tried a lot of combinations but the converter has not been invoked. As soon as I put the converter tag inside the composite component definition, it works.

为了使事情变得简单,让我们假设我有以下内容:

To make things easier, let's assume I have the following:

<composite:interface>
   <composite:attribute name="value" required="true"/>
</composite:interface>

<composite:implementation>
   [...]
   <h:selectManyCheckbox id="#{cc.attrs.id}" value="#{cc.attrs.value}">
        <composite:insertChildren/>
   </h:selectManyCheckbox>
   [...]
</composite:implementation>

该组件的用法如下:

<my:selectManyCheckbox id="myComponent" value="...">
   <f:selectItems value="..."/>
   <o:converter for="___" converterId="..."/>
</my:selectManyCheckbox>

也许有人可以给我提示应该为"for"属性赋予什么值.

Perhaps someone can give me a hint what value should be given to the 'for' attribute.

推荐答案

我自己找到了答案.您可以使用以下

I found the answer myself. You can use the following

<composite:interface>
    <composite:attribute name="value" required="true"/>
    <composite:editableValueHolder name="input_component">
</composite:interface>

<composite:implementation>
    [...]
    <h:selectManyCheckbox id="input_component" value="#{cc.attrs.value}">
        <composite:insertChildren/>
    </h:selectManyCheckbox>
    [...]
</composite:implementation>

重要的部分是 editableValueHolder 标记.现在,在使用此复合组件的页面上,您可以使用

The important part is the editableValueHolder tag. From the page using this composite component, you can now use

<o:converter for="input_component" converterId="id_of_converter" />

这是对我有用的解决方案.我希望这可以帮助其他有相同问题的人.

This is the solution that is working for me. I hope this helps others having the same problem.

这篇关于使用转换器时如何在复合组件内部引用组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆