1

I create a link in my composite JSF component:

<h:link id="menu-abc" outcome="/abc" value="ABC" />

The link is not within a form. However, when I look at the rendered HTML code there is a dynamically generated ID as prefix to my id:

<a id="j_idt33_menu-abg" name="j_idt33_abv" href="abc.xhtml">ABC</a>

I cannot find out where this dynamic id comes from. Any ideas?

ps: we changed the separator character from : to _

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
bertolami
  • 2,896
  • 2
  • 24
  • 41

1 Answers1

3

The symptoms suggests that you actually don't have a custom component at all, but a composite component and that you've changed the NamingContainer separator character from : to _ for some reason.

Composite components are by themselves naming containers and prepend the ID of all their children with their own ID. The simple reason is because they can be reused multiple times in a single view. If the composite component's own ID wasn't prepended, it would have resulted in duplicate IDs in the component tree.

In a real custom component you'd have full control over the client ID.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • thanks. I changed the question to composite compontent. And I finally found out that I missed an Id on the composite component usage. – bertolami Nov 19 '12 at 12:48
  • The separator character change to `_` has serious implications. The autogenerated client ID of JSF uses by itself also that character. So you absolutely need to give all your components (at least, those which you'd like to reference elsewhere, e.g. h:message, f:ajax, etc) a fixed ID without that character. Otherwise `UIComponent#findComponent()` may greatly fail. Here's a related and possibly enlightening read: http://stackoverflow.com/questions/10726653/ – BalusC Nov 19 '12 at 12:52