Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using JSF h:outputLink to produce a page anchor

Simple question:

How do you create an HTML anchor like

<a id="organization" />

with JSF, e.g.

<h:outputLink ... />

or another JSF link component? Is it possible at all?

like image 988
Kawu Avatar asked Jan 11 '13 10:01

Kawu


People also ask

How do I create an On page anchor in HTML?

In the text editor, click SOURCE. Navigate to where you want to insert an anchor. In the HTML code, insert the anchor using the format id=“anchor_name” within the <p> tag. Note: IDs on a page must be unique, and can't be re-used for other anchors.

What is anchor attribute?

An anchor is a piece of text which marks the beginning and/or the end of a hypertext link. The text between the opening tag and the closing tag is either the start or destination (or both) of a link. Attributes of the anchor tag are as follows. HREF.


1 Answers

You could use <h:link> for that. Its id attribute becomes the <a id> and <a name>.

<h:link id="organization" value="Organization" fragment="organization" />

It generates the following HTML:

<a id="organization" name="organization" href="/currentcontext/currentpage.xhtml#organization">Organization</a>

But just using plain <a> or even <span> or <div> is perfectly legal in JSF/HTML as jump targets.

<span id="organization">Organization</span>

In order to create a link which jumps to that, use <h:link fragment> without id:

<h:link value="Jump to organization" fragment="organization" />

The generated HTML will look like this:

<a href="/currentcontext/currentpage.xhtml#organization">Jump to organization</a>
like image 135
BalusC Avatar answered Oct 26 '22 01:10

BalusC