Search |
||
Using an IDE to write a JSF 2.0 AppPosted by driscoll on May 18, 2009 at 9:40 AM PDT
So, you're on the cutting edge, writing JSF 2.0 applications, but you just get tired of jkl; editing in vi... You can still do JSF 2.0 applications using your IDE, but the price is that you won't have some of the on the fly error checking (especially in your Facelets page).
First, a little about the status of various support efforts - unfortunately, tools support will lag for JSF 2.0, just as it has in other major releases. I've checked on three different IDEs -
I'll run through using both Eclipse and NetBeans with JSF 2.0, but first, a word about what you'll get when you're done - you'll have a nice GUI editor that handles the JSF 2.0 Java classes just fine, but will treat the XHTML as simple XHTML, without knowing any of the Facelets content. So, it'll tell you if you've mismatched a tag, but if you misspell, for instance, h:commandButton as h:commandbuttn, it's up to the server to tell you that when you view the page. Better support will be forthcoming, as I mentioned above, but for now you'll have to be patient. Also, I'm hardly an expert at either platform, so for those of you who are, comments and suggestions are always welcome.
Instructions for Using Eclipse with JSF 2.0First, go download a version of Eclipse that bundles GlassFish, or some other server that supports JSF 2.0.From that page:
Install and launch it. Alternatively, you can use your existing Eclipse 3.4 Ganymede installation and get the GlassFish plugin for Eclipse. Read these instructions to find out how. To create the project: File ... New ... Dynamic Web Project Opens a Wizard. Project Name: JSF 2.0 Test
Target Runtime: push "New" button, choose Glassfish V3 PROMOTED
Choose your VM (on my Mac, it was the default 1.6) The next page, you should be able to just accept all the defaults. Click "Finish". You've now configured your Target Runtime to be something that supports JSF 2.0. Since the rest of the values that you need are all the defaults, you can go ahead and click "Finish" again". In particular, you don't need to select the "JSF" runtime configuration - since you won't really be using the faces-config.xml file, anyway - since for most uses, it isn't necessary for JSF 2.0. Your Project is now set up. You should know what to do next - create a JSF 2.0 app. You can delete the index.jsp page, and fill in with a bunch of xhtml files... The Eclipse IDE knows about the new JSF 2.0 APIs, since by default it uses the API jars bundled into the server. Here's an example of a project file structure that I did that worked, just so you can see what files you'll have to change.
Instructions for Using Netbeans with JSF 2.0You'll need to download the latest NetBeans Nightly Build (no, Beta won't do, since that has a few showstopper bugs for our use).You'll also need the latest release of GlassFish v3 nightly. (Remember, you're cutting edge, right?) If you're just going after JSF 2.0, though, you could always just use GlassFish v3 Prelude updated to the latest Mojarra release, as described in the release notes. If you're using GlassFish v3, then you'll need to add the plugin to make that work. Once all that's done, it's easy - just create a standard JSF project, using the v3 server that you downloaded, just like any other JSF project that you create. You'll need to delete the faces-config.xml file, and change the web.xml file a bit, but like in Eclipse, the server acts as the repository for the requisite APIs. I've attached a sample file to the blog so you can see an example to work from. »
Related Topics >>
Glassfish Comments
Comments are listed in date ascending order (oldest first)
Submitted by juergen_zimmermann on Mon, 2009-05-18 10:59.
JBossTools http://www.jboss.org/tools/ are basically a set of Eclipse plugins. They are supporting Facelets 1,1,x
Submitted by cayhorstmann on Tue, 2009-05-19 07:11.
For some reason, I haven't been able to use Glassfish v3 with the latest Mojarra builds. But Eclipse works fine with Tomcat and Mojarra. (1) Add the jsf-api.jar and jsf-impl.jar to your project (2) In Properties -> Java Module Dependencies, select these JARs. That way, they get added to the WEB-INF/lib directory.
Submitted by arungupta on Tue, 2009-05-19 09:04.
Great summary!
I also blogged about JSF 1.x and Eclipse at:
http://blogs.sun.com/arungupta/entry/totd_54_java_server_faces
Submitted by kvillaca on Fri, 2009-05-22 00:03.
Hi,
I did all those steps, although after the Eclipse with the GlassFish plugin have finished the download, and I have clicked finish and finish again. I can't see any options to create projects for JSF2. When I have created one Dynamic Web Projetc and have deleted the index.jsp I just can't create any file with .xhtml extension simple because the IDE does not recognized as a view file. I have the GlassFish Promoted into server place. when I went check the properties from my project it is showing JSF 1.1 and even clicking into down row, I just can see the 1.2
What I did wrong ?
Thanks
Submitted by frankwhofmann on Fri, 2009-05-22 06:32.
Referring to your example of a misspelled JSF tag:
Maybe I have missed something, but isn't it that the only thing an IDEs XML/XHTML editor would need to appropriately support syntax checking and code completion is a set of XML schema definitions covering the JSF standard tags (including facelet tags providing templating) and any 3rd party component libraries in use?
Testwise I am maintaining a XSD file declaring my own custom JSF tags and their attributes, because I don't expect my IDE to understand, which java files are going to be packed into a component library and what the JSF annotations mean. Theoretically we should be able to generate an XSD automatically from the annotations, but the effort to create an appropriate schema is very small compared to the many usages of the schema (this applies all the more to the JSF/Facelet tags).
Submitted by driscoll on Tue, 2009-05-26 10:41.
kvillaca:
Yes, you'll only see 1.2. that's expected, and I should have mentioned that.
frank:
Since xsds exist for the new features, it apparently requires more than that - but since I don't write IDE plugins, I couldn't say what.
Submitted by ntruchsess on Wed, 2009-05-27 15:07.
jim + frank:
All one has to do to enable xsd-support in a reasonable good xml-editor is specifying a valid xsi:schemaLocation-attribute for each namespace being used. Without xsi:schemaLocation an xml-editor will only support schema that are known to the editor.
In eclipse it's possible to extend the set of well-known schema in xml-preferences so you don't have to specify xsi:schemaLocation after installing the xsds into eclipse.
Submitted by driscoll on Wed, 2009-05-27 19:03.
ntruchsess: Thanks for the tip - you can also do that in Netbeans as well. And that will help with some of the issues.
But unfortunately that still won't fully do the job, since at least the composite component feature isn't amenable to that solution.
As I said, if it was really just that easy, they'd have done it already.
|
||
|
|