Search code examples
jsfhyperlinkhref

Refer an element to the DOM with h:link


My question is simply, it's possible make a href to a element of the DOM?

Something like this:

  <h:link outcome="page#form" value="Edit"></h:link>

That's would print something like this:

   <a href="/page#form.jsf">Edit</a>

Obviously, I tried this and didn't work, It can be done in JSF? And if can... which tag I must use?

Regards!


Solution

  • You need to use the fragment attribute of <h:link> to bring the identifier of the requested page into focus:

    <h:link value="Edit" outcome="/page" fragment="form" />
    

    Though using plain HTML elements, like a, or span, or any other, is perfectly valid as well.

    Of course, you could also use <h:outputLink> for that purpose.