0

I have a facelets tag like this:

<ui:composition>
    <h:outputText value="#{label}"/>
    <h:inputText id="input" value="#{value}"/>
    <h:message for="input"/>
</ui:composition>

Now if I inlcude this facelets tag twice on the same page, I get an exception complaining about duplicate compoment ids. One solution proposed here https://stackoverflow.com/a/21572756/1785730 was to supply a prefix for the id. However, I find it cumbersome having to come up with an id prefix every time I use this facelets tag. By the way, I don't need the id of the h:inputText outside of the tag.

So I'm thinking of two ways how I can fix this:

  1. Is there a way to link the h:message to the h:inputText without having to specify ids?
  2. If not, I could wrap the tag with a NamingContainer. Which element would be appropriate for that? I can't use h:form here, because that tag already goes into a form.
Community
  • 1
  • 1
user1785730
  • 3,150
  • 4
  • 27
  • 50
  • Why not do '3' from the link you refer to? – Kukeltje Nov 21 '16 at 14:40
  • I was looking for a more lightweight solution. I'd prefer to stay with facelets. – user1785730 Nov 21 '16 at 14:41
  • Besides, composite components are *one* component in the end. My tag fits right into a three column h:panelGrid. – user1785730 Nov 21 '16 at 14:51
  • 1) would otherwise already be covered by the answer you found. 2) is already covered by the answer you found. So I'm not really understanding why you're asking this duplicate question. – BalusC Nov 22 '16 at 09:53
  • In case you're refering to f:subview: that has a required id parameter, which doesn't get me any further. If I just can't do it the way I want and my best bet is to have an id parameter for my tag, that would be an acceptable answer. – user1785730 Nov 22 '16 at 11:18

1 Answers1

-2

Your page should be like this

<f:view contracts="default" transient="false">
    <ui:composition template="/template.xhtml">
        <ui:define name="content">
            <h:form>
                inputs
            </h:form>
        </ui:define>
    </ui:composition>
</f:view>

inside ui composition you should have ui define and in it form and inputs.

user1785730
  • 3,150
  • 4
  • 27
  • 50
Armen Arzumanyan
  • 1,939
  • 3
  • 30
  • 56
  • 1
    How would that solve the duplicate id exception when including my tag twice? – user1785730 Nov 22 '16 at 08:51
  • In every form every tags must have unique id. the first improve your page, you are using facelets composition without main template, second be sure what in every h:form components have unique id. – Armen Arzumanyan Jan 14 '17 at 19:32