Using JSF h:outputLink to produce a page anchor

前端 未结 3 1531
鱼传尺愫
鱼传尺愫 2021-01-05 01:17

Simple question:

How do you create an HTML anchor like


with JSF, e.g.



        
相关标签:
3条回答
  • 2021-01-05 01:48
    <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>

    0 讨论(0)
  • 2021-01-05 02:00

    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>
    
    0 讨论(0)
  • 2021-01-05 02:01

    Why not use

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

    or if its on the same page just

    <h:outputLink value="#anchor" />    
    
    0 讨论(0)
提交回复
热议问题