My blog has moved!

You should automatically be redirected in 6 seconds. If not, visit
http://blogs.i2m.dk/allan
and update your bookmarks.

Thursday, 8 May 2008

Using Facelets with NetBeans 6.1 (without nbfaceletssupport)

--
Update 27. May 2008: You can download the Facelets NetBeans plug-in for 6.1 from: http://project-template.googlecode.com/files/nbfaceletssupport-6.1.zip
--

I'm a fan of Facelets when it comes to templating for JSF applications. Prior to version 6.1 of NetBeans I was using the nbfaceletssupport plug-in. Sure, it had its quirks, but overall it was a good plug-in. After installing NetBeans 6.1 and really got into using all the new cool features (shared libraries being the most significant) I realised that the nbfaceletssupport plug-in for NetBeans 6.0 didn't work and a fix had not yet been released at the nbfaceletssupport project site (note: Po-Ting Wu of Sun Microsystems has provided instructions on how to re-compile the plug-in for NetBeans 6.1). This also happened when I switched from NetBeans 5.5.1 to 6.0, so I anticipate that this will also happen in the future. So, I thought to myself, why not use the powerful XML support already built-in NetBeans to give me what I need. What I really needed the plug-in for is code completion. So, here goes. First I decided to drop JSP pages (.jsp) for JSP documents (.jspx). The difference being that .jspx is pure XML and .jsp is HTML.

Facelets file as a JSP page (.xhtml):


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html">
<head>
<title>JSP facelets file</title>
</head>
<body>

<ui:composition template="/resources/templates/page.xhtml">
<ui:define name="pageTitle">This is a page title</ui:define>
<ui:define name="pageContent">This is the page content</ui:define>
</ui:composition>

</body>
</html>



Facelets file as a JSP document (.jspx):

<jsp:root version="2.0" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:t="http://myfaces.apache.org/tomahawk" xmlns:c="http://java.sun.com/jstl/core" xmlns:jsfExt="http://java.sun.com/jsf/extensions/dynafaces">
<ui:composition template="templates/page.xhtml">
<ui:define name="pageTitle">This is a page title</ui:define>
<ui:define name="pageContent">This is the page content</ui:define>
</ui:composition>
</jsp:root>



When creating facelets file as JSP document in NetBeans you will automatically get code completion (without any third-party plug-ins).



For this to work, ensure that the following configuration is set it web.xml:


<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.jspx</param-value>
</context-param>



and that the faclets tag library descriptor (TLD) is accessible in the classpath (eg. /WEB-INF/tlds).




References:

Tuesday, 6 May 2008

Yearly conference at the local Danish IT Society branch

Last week I went to the yearly conference for my local Danish IT Society branch. The topic of the conference was Enterprise Architecture. I was a bit unsure about attending as I was expecting some obscure high-level talks that has never seen the light of day. I was pleasantly surprised! All the speakers did a great job and managed to cover the various facets (from theory, to best practice, to practice) of Enterprise Architecture. What especially caught my attention was the excellent governance and organisational re-structuring implemented at NyKredit headed by their CIO (and president of Danish IT Society) Lars Mathiesen (You can read articles about Mathiesen on Computerworld.dk). From a vendor point-of-view the Vice President SOA Strategy, Ivo Totev of Software AG flew in from Germany. Last year I went for another meeting arranged by Danish IT Society with Scrum founder Jeff Sutherland. I wasn't too impressed as there was too much "going-around-the-bush" and not a clear business case for Scrum. Anyways, I didn't know what to expect from Ivo Totev's presesentation. However, I was very impressed with his presentation about the best practices of Enterprise Architecture coupled with anecdotes about what was working and not working with their clients. If you've got interest in Enterprise Architecture, Service-oriented Architecture (SOA), and Business Process Management, I suggest visiting Software AG's customer community at http://communities.softwareag.com/ where you'll interesting resources such as podcasts, blogs, discussion groups and even a freely downloadable PDF version of the book "BPM Basics for Dummies".