How to include another XHTML in XHTML using JSF 2.0 Facelets?

<ui:include> Most basic way is <ui:include>. The included content must be placed inside <ui:composition>. Kickoff example of the master page /page.xhtml: <!DOCTYPE html> <html lang=”en” xmlns=”http://www.w3.org/1999/xhtml” xmlns:f=”http://xmlns.jcp.org/jsf/core” xmlns:h=”http://xmlns.jcp.org/jsf/html” xmlns:ui=”http://xmlns.jcp.org/jsf/facelets”> <h:head> <title>Include demo</title> </h:head> <h:body> <h1>Master page</h1> <p>Master page blah blah lorem ipsum</p> <ui:include src=”/WEB-INF/include.xhtml” /> </h:body> </html> The include page /WEB-INF/include.xhtml (yes, this is the … Read more

What can , and be used for?

Process GET parameters The <f:viewParam> manages the setting, conversion and validation of GET parameters. It’s like the <h:inputText>, but then for GET parameters. The following example <f:metadata> <f:viewParam name=”id” value=”#{bean.id}” /> </f:metadata> does basically the following: Get the request parameter value by name id. Convert and validate it if necessary (you can use required, validator … Read more

JSF returns blank/unparsed page with plain/raw XHTML/XML/EL source instead of rendered HTML output

There are three main causes. FacesServlet is not invoked. XML namespace URIs are missing or wrong. Multiple JSF implemenations have been loaded. 1. Make sure that URL matches FacesServlet mapping The URL of the link (the URL as you see in browser’s address bar) has to match the <url-pattern> of the FacesServlet as definied in … Read more

Differences between action and actionListener

actionListener Use actionListener if you want have a hook before the real business action get executed, e.g. to log it, and/or to set an additional property (by <f:setPropertyActionListener>), and/or to have access to the component which invoked the action (which is available by ActionEvent argument). So, purely for preparing purposes before the real business action … Read more

How to find out client ID of component for ajax update/render? Cannot find component with expression “foo” referenced from “bar”

Look in HTML output for actual client ID You need to look in the generated HTML output to find out the right client ID. Open the page in browser, do a rightclick and View Source. Locate the HTML representation of the JSF component of interest and take its id as client ID. You can use … Read more

JSTL in JSF2 Facelets… makes sense?

Introduction JSTL <c:xxx> tags are all taghandlers and they are executed during view build time, while JSF <h:xxx> tags are all UI components and they are executed during view render time. Note that from JSF’s own <f:xxx> and <ui:xxx> tags only those which do not extend from UIComponent are also taghandlers, e.g. <f:validator>, <ui:include>, <ui:define>, … Read more

How to choose the right bean scope?

Introduction It represents the scope (the lifetime) of the bean. This is easier to understand if you are familiar with “under the covers” working of a basic servlet web application: How do servlets work? Instantiation, sessions, shared variables and multithreading. @Request/View/Flow/Session/ApplicationScoped A @RequestScoped bean lives as long as a single HTTP request-response cycle (note that … Read more

commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated

Introduction Whenever an UICommand component (<h:commandXxx>, <p:commandXxx>, etc) fails to invoke the associated action method, or an UIInput component (<h:inputXxx>, <p:inputXxxx>, etc) fails to process the submitted values and/or update the model values, and you aren’t seeing any googlable exceptions and/or warnings in the server log, also not when you configure an ajax exception handler … Read more