Thursday, January 4, 2007

Dynamically switch between subviews in one main page

The easiest way would be the following:

<jsp:include page="#{myBean.includePage}"/>

But this only works in JSF 1.2 + JSP 2.1 or newer. Unified Expression Language (the expressions starting with #) namely made its way from JSF to JSP in JSP 2.1. In older versioned environments the above snippet is not valid. To have JSP 2.1, you need a Servlet 2.5 compatible servletcontainer and a web.xml which is declared as per Servlet 2.5 specification.

The JSP 2.0 trick

If you're still using the old JSF 1.1 + JSP 2.0 (Servlet 2.4), then it's good to know that you can also access JSF managed beans using the old JSP EL notation ${managedBeanName}! You only have to keep in mind that this doesn't precreate the managed bean automatically when this line is called for the first time. So somewhere in the code before this line you should already have called the managed bean by JSF EL. The following example will work:

About

Donate

For the ones who want to express their excessive thanks for my work, I used to have an Amazon wishlist with a list of books, but right now I don't have any interesting books on the list anymore (to anyone who've sent books before: thank you very much, I got 6 books in 6 months). You can always donate something so that I can use it for other stuff, such as Nespresso coffee.