title: How get the base URL via context path in JSF?
body: <p>I have this structure:</p>
  
  <pre class="lang-none prettyprint-override"><code>WebContent
      resources
          components
              top.xhtml
  
      company
          about_us.xhtml
  
      index.xhtml
  </code></pre>
  
  <p><code>top.xhtml</code> is a component, that is used in <code>index.xthml</code> and <code>about_us.xhtml</code> too.</p>
  
  <p><code>top.xhtml</code></p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;ul&gt;
      &lt;li&gt;&lt;a href="index.xhtml"&gt;Home&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="company/about_us.xhtml"&gt;About us&lt;/a&gt;&lt;/li&gt;
      ...
  &lt;/ul&gt;
  </code></pre>
  
  <p>So my problem is, when the current page is <code>index.xhtml</code> the component generates URLs correctly, but when the current page is <code>about_us.xhtml</code>, it generates wrong URLs. I cannot use relative path because it's going to generate the wrong URL too. I think it is because the component is based on the current path of the <code>*.xhtml</code> page.</p>
  
  <p>The only solution I could found out is:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;ul&gt;
      &lt;li&gt;&lt;a href="${pageContext.request.contextPath}/webname/index.xhtml"&gt;Home&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="${pageContext.request.contextPath}/webname/about_us.xhtml"&gt;About us&lt;/a&gt;&lt;/li&gt;
      ...
  &lt;/ul&gt;
  </code></pre>
  
  <p>But I think is not 'elegant' at all. Any ideas?</p>