Thursday, November 2, 2006

Using JDK 5 language features in Creator

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


As you're probably well aware of, there were several important releases this week. First, NetBeans 5.5 was
released. This has been covered extensively by other Sun bloggers
so I won't repeat the highlights here - just check it out if you haven't already.



Second, a number of add-on packs for NetBeans 5.5 were released. A pack is a cluster of plugins.
One of these is the

Visual Web Pack
, which basically bundles all the visual web page design functionality from Creator into NetBeans. With this, you can create pages Creator style alongside other NetBeans features, such as the profiler, or the UML tool, or the enterprise XML support.



There's another big reason why even Creator users should try the visual web pack (which is in technology preview state, not a final release like NetBeans 5.5.). It offers new support for Java 5 language features, as well as Java EE 5 support. I took it for a quick testspin and thought I would show it in action here.



If you download NetBeans 5.5, and then the Visual Web Pack installer, you can create Visual Web Projects. Unfortunately, out of the box, it will only offer to create J2EE 3 and J2EE 4 projects. The reason for this is that NetBeans is only bundled with the Tomcat web container, and Tomcat is not adequate for Java EE 5 projects. Thus, the trick is to also download a Java EE 5 capable app server such as Glassfish or its cousin, the Sun Application Server. Once you've done that, and you select it as the target in the new project dialog, you are able to create a Java EE 5 project. Hopefully we'll have everything ready as a single bundle so that out of the box, you're defaulting to Java EE 5 projects and Java 5 source. Here's the configuration portion of the New Project wizard (click Manage to register additional web servers).






Let's create a simple web app which utilizes Java 5 features. It will be a simple page which lets you provide the name of a Java class, and then the methods (possibly generic) of the class are displayed. Here's what the web app looks like in the designer:






Here's the button click event handler:






Note that we simply use the error method to log messages for the page; these are all displayed in the group message component. This is a very simple way to log messages for ourself during debugging. You should always have a Message Group component, on every single page of your application, during development. This will make it immediately obvious if you have validation errors or other problems that might otherwise silently occur and leave you scratching your head.



When we run and try it with some sample data, here's the result which shows Java 5 language features in action:






The next step is to play with Java EE 5 features mixed with JSF. That will have to wait for another day; I've gotta get back to my day job, which I'll blog about soon.


6 comments:

  1. It is cool but I don't want to be strapped to the SJAS.

    ReplyDelete
  2. I bet it works with any other Java EE 5 containers too. NetBeans 5.5 supports deployment to BEA Weblogic 9.0 and 9.1, JBoss 4.0.3 an possibly others; I haven't tried these but if they support Java EE 5 I bet Creator would let you use Java 5 features with them.

    ReplyDelete
  3. The NetBeans 5.5 and SJSAS 9.0 UR1 bundle is already out:
    http://www.netbeans.info/downloads/index.php?rs=14&p=3

    ReplyDelete
  4. @Bob: note also that if you don't want a Sun-branded product (although it's free and optionally supported), you can use GlassFish and register it using the "Sun AS" UI-choice.

    ReplyDelete
  5. This is just a *glorious* development. Finally being able to use Java EE 5 features with "Creator"--better yet, a Creator within NetBeans--is something I have been *dying* to have. I think this really ushers in a new era where JSF and EJB3 will be able to play nicely together as was always intended--this could be a turning point in bringing EE 5 to the forefront. In any case, developers like me will be eating this up!

    ReplyDelete
  6. This is a great step by itself, but the whole JSF effort is too fragmented and uncoordinated. This visual designer doesn't even support the better JSF UI enhancements such as Facelets or Clay and only supports the antiquated and flawed JSP/JSF approach. How well does this work with Tomahawk or Tobago or ICEFaces or ajax4jsf or any of the dozen other component libraries or JSF sub-frameworks? What JSF needs is less chaos and sub-frameworks and more central coordination and aggressive improvement. The fundamentals of JSF haven't been improved in years and have stagnated leaving plenty of issues unresolved.
    Sorry to sound negative. This piece is great engineering by itself. I really want to see these various technologies develop into a best of breed web development solution, but I think the various teams involved are too framented and uncoordinated, and the overall quality of the development solution really suffers.

    ReplyDelete