Request parameters are configured in the JSF bean on @ManagedProperty.
@ManagedProperty(value="#{param.page}")
private String page;
(this is basically a bean.setPage(request.getParameter("page"))immediately after building the bean)
You can use EL in Facelets <ui:include>.
<ui:include src="#{bean.page}.xhtml" />
(if it bean.getPage()returns profile, the value will turn out as profile.xhtmland accordingly included)
No need for legacy servlets :)
Update : You set the annotation in the wrong place. This should look like in my original answer:
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;
}
}
, @ManagedBean, 1- ( , ). @RequestScoped, bean. , Java.
<managed-bean> faces-config.xml JSF 2.0. . .
2: index.xhtml :
<!DOCTYPE html>
<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">
<h:head>
<title>Include demo</title>
</h:head>
<h:body>
<h1>This is the index page</h1>
<c:catch>
<ui:include src="#{selector.page}.xhtml" />
</c:catch>
</h:body>
</html>
(<c:catch> FileNotFoundException , )
include.xhtml :
<!DOCTYPE html>
<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">
<h2>Include page content</h2>
</ui:composition>
, FacesServlet url-pattern *.xhtml, , index.xhtml?page=include.