Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Request parameters are settable in JSF bean by <a href="http://download.oracle.com/javaee/6/api/javax/faces/bean/ManagedProperty.html" rel="nofollow"><code>@ManagedProperty</code></a>.</p> <pre><code>@ManagedProperty(value="#{param.page}") private String page; </code></pre> <p><em>(this does basically a <code>bean.setPage(request.getParameter("page"))</code> directly after bean's construction)</em></p> <p>You can use EL in Facelets <a href="http://download.oracle.com/javaee/6/javaserverfaces/2.0/docs/pdldocs/facelets/ui/include.html" rel="nofollow"><code>&lt;ui:include&gt;</code></a>.</p> <pre><code>&lt;ui:include src="#{bean.page}.xhtml" /&gt; </code></pre> <p><em>(if <code>bean.getPage()</code> returns <code>profile</code>, the value would end up as <code>profile.xhtml</code> and included accordingly)</em></p> <p>No need for legacy servlets :)</p> <hr> <p><strong>Update</strong>: you've set the annotation at the wrong place. It should look like this, exactly as in my original answer:</p> <pre><code>package beans; import javax.faces.bean.ManagedProperty; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; @ManagedBean @RequestScoped public class Selector { @ManagedProperty(value="#{param.page}") private String page; public String getPage() { return page; } public void setPage(String page) { this.page = page; } } </code></pre> <p>Note that I omitted the <code>@ManagedBean</code> name since the default value is already the classname with 1st character lowercased (which is exactly the same as you specified manually). I also added the <code>@RequestScoped</code> annotation to specify the bean scope. I also lowercased the packagename since uppercases are disallowed in package name as per standard <a href="http://www.oracle.com/technetwork/java/codeconventions-135099.html#367" rel="nofollow">Java Naming Conventions</a>.</p> <p>The whole <code>&lt;managed-bean&gt;</code> in <code>faces-config.xml</code> is <a href="http://blogs.oracle.com/rlubke/entry/faces_config_xml_we_don" rel="nofollow">entirely superfluous</a> with the new JSF 2.0 annotations. You're basically duplicating it. Remove it.</p> <hr> <p><strong>Update 2</strong>: the <code>index.xhtml</code> should look like this</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang="en" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:c="http://java.sun.com/jsp/jstl/core"&gt; &lt;h:head&gt; &lt;title&gt;Include demo&lt;/title&gt; &lt;/h:head&gt; &lt;h:body&gt; &lt;h1&gt;This is the index page&lt;/h1&gt; &lt;c:catch&gt; &lt;ui:include src="#{selector.page}.xhtml" /&gt; &lt;/c:catch&gt; &lt;/h:body&gt; &lt;/html&gt; </code></pre> <p><em>(the <code>&lt;c:catch&gt;</code> is there to suppress the <code>FileNotFoundException</code> whenever there's no such file)</em></p> <p>The <code>include.xhtml</code> should look like this:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;ui:composition xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets"&gt; &lt;h2&gt;Include page content&lt;/h2&gt; &lt;/ui:composition&gt; </code></pre> <p>Assuming that <code>FacesServlet</code> is listening on <code>url-pattern</code> of <code>*.xhtml</code> and the both files are in the same folder, open it by <code>index.xhtml?page=include</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload