Is there anything better for creating absolute links?

Is the best way to create absolute links in JSF 2.0? Right now, I'm using <h:outputLink/> in this ugly key with #{facesContext.externalContext.requestContextPath} , as shown below. I do not want to use JSTL and <c:url />

 <h:outputLink value="#{facesContext.externalContext.requestContextPath}/pages/home.jsf">Home</h:outputLink> 
+6
source share
1 answer

You can shorten #{facesContext.externalContext.requestContextPath} to #{request.contextPath} . You can even get rid of it instead of the HTML <base> .

In this particular case, it is better to use <h:link> . In the outcome attribute, it can take a context-sensitive navigation path:

 <h:link value="Home" outcome="pages/home" /> 

JSF will take care of adding the correct context path and FacesServlet display when creating the <a> element:

 <a href="/contextname/pages/home.jsf">Home</a> 

See also:

+11
source

Source: https://habr.com/ru/post/900593/


All Articles