JSf + Eclipse on a Mac
December 16, 2007 . Posted in java.
Today I will start a new thread in my blog that will cover the good, the bad and the ugly of developing a JSF application on a MacBook using Eclipse.
The tools that I use will include:
– Sun’s JSF RI.
– Eclipse 3.3+
– JPA (using Hibernate or Toplink as the Persistence Provider)
– Tomcat 6 / JBoss 4.2 / Glassfish V2 as application servers
I will not cover installing these tools on Mac OS X 10.5 Leopard as there are lots of tutorials on how to do this. What I will cover are useful things that I find while working with these tools and libraries.
So let’s get started.
Setting up the project in Eclipse is as easy as going to New -> Project -> Dynamic Web Project. If you haven’t defined the JSF library yet follow this tutorial.
Here comes the first tip. I found it annoying to have to manually include the JSF taglibraries every time when I created a new JSP page. Sure you can have include pages where you define all this but I believe Eclipse should come with another JSP template that is tailored for JSF developers. So let’s fix this:
– hit Command + , in Eclipse to get to the preferences page.
– type Templates in the filter text field
– click the Templates entry under JSP Files
– now hit the New button and fill in the information like in my example:- make sure to put the taglibs as in my example. tip: copy the contents from the New JSP template and jusst add the taglibs
- save the dialog
Now you have a new JSP template. Here is how you use it.
– hit Command + N to launch the New … wizard
- type JSP and select the JSP entry under Web
- hit Next and select the destination for the file
- type a file name and hit Next
- now you should see the Template that you have created earlier
- that’s all…
I know I know, lots of instructions for a simple effect. You will find this useful though when you will create lots of JSF pages and you will realize that you need not do any imports or includes to get taglib support in your page.
And since you’ve been so patient here’s another tip. I am very annoyed when I read the rendered HTML code and I see all those blank lines in my markup. JSP 2.1 loves developers like me and it provides this useful directive:
<%@page trimDirectiveWhitespaces="true"%>
Using this directive will make sure that there are no empty lines in the generated HTML code.
If you want to use this all the time just add it to your templates like I’ve shown you. Just make sure you are using JSP 2.1…
This is enough for now…
Cheers

Post a comment