How to reference component inside a composite component when using a converter

青春壹個敷衍的年華 提交于 2019-12-10 20:23:43

问题


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/>

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).

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.

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>

This component should be used as follows:

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

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


回答1:


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>

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.



来源:https://stackoverflow.com/questions/38919946/how-to-reference-component-inside-a-composite-component-when-using-a-converter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!