Using JSF h:outputLink to produce a page anchor

孤人 提交于 2019-11-30 03:30:41

问题


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?


回答1:


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>



回答2:


Why not use

<h:outputLink value="www.yourweb/somePage#anchor" />

or if its on the same page just

<h:outputLink value="#anchor" />    



回答3:


<h:link value="test" outcome="icerik">
    <f:param name="id" value="#{icerik.id}" />
</h:link>

This links to icerik.xhtml?id=2 and seems like <a href="icerik.xhtml.?id=2">test</a>



来源:https://stackoverflow.com/questions/14276600/using-jsf-houtputlink-to-produce-a-page-anchor

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