|  | David Geary discusses JSF, Ajax, and GWT by Kito Mann 16 Jul 2008 02:00 EDT |
This podcast is an interview between JSFCentral editor-in-chief Kito D. Mann and David Geary, the president of Clarity Training, Inc., where he teaches developers to implement web applications using JSF, GWT, and Grails. It was recorded in May of 2007 at the JavaOne conference in San Francisco, CA. You can catch David Geary and other expert JSF speakers at JSFOne.
Podcast (MP3)
Welcome to the JSFCentral podcast #4 for the week of July 14th, 2008. This series of podcasts features interviews, news, and commentary for those working with JavaServer Faces technology.
We're proud to announce JSFOne, the one event exclusively focused on the JSF Ecosystem, taking place September 4th-6th in Vienna, VA. JSFOne is a conference for application developers, solution architects, and project managers who develop applications with JavaServer Faces, Seam, and related technologies. Our speakers are deeply involved in every aspect of the JavaServer Faces ecosystem – from developing core technologies to building real-world applications. JSFOne is hosted by JSFCentral No Fluff Just Stuff Symposiums.
| Kito | Hello, my name’s Kito Mann. I am here with David Geary at JavaOne 2007. We are sitting outside at the Samovar Tea Lounge which doesn’t actually have any normal food, but that’s okay. Alright so David, tell us who you are and what you do?
| | David | What I do currently is – I essentially do three things – I write books once in a while; once a year I come out with a new book. I do training, and I do speaking with the No Fluff Just Stuff Tour.
| | Kito | Okay, and for those people who haven’t read any of your books – the three of them out there?
| | David | I started in the late 90’s. I wrote a Swing book and an AWT book. Then unfortunately I had to go to the server side and deal with that for a few years. I wrote a book on JSTL and a JSP book. My most recent book is Core JavaServer Faces which I wrote with Cay Horstmann, and I just finished a book on the Google Web Toolkit.
| | Kito | And when is the GWT book coming out?
| | David | Last week – it’s not quite out yet but should be real soon.
| | Kito | This was the book that they hoped to get out by JavaOne but they didn’t quite make it.
| | David | Yeah well, as you probably well know, that’s kind of how the Java publishing industry works. We would like to get our books out by JavaOne so we can get kind of a kick start for it, but we just missed the boat with this. We are in the final editing stages now. It should be out within the next three or four weeks.
| | Kito | Cool. Alright, so you have been touring with No Fluff Just Stuff – what kind of topics have you been talking about?
| | David | I have a number of JSF talks. I have an intro to JSF talk that I have been doing now – I have been on the tour for four years. Interestingly enough, attendance has never really dropped off on that talk. I think a lot of people are still slow to move from Struts. It’s amazing; I see 60-80 % of attendees at the conferences are still using Struts.
| | Kito | Wow.
| | David | I think there are still people moving to JSF that are new to it and haven’t used it, which is good for me because I always get good attendance at my talks. It’s good for my books because they are still selling pretty well. I also have a talk on JavaScript frameworks: Prototype, Scriptaculous, and a framework called Rico. I do a couple talks on Seam, Ajax4Jsf, and Facelets, which is a really nice stack of technologies. I also have two talks this year on the Google Web Toolkit which is an absolutely awesome toolkit.
| | Kito | Okay. Let’s just delve into some of these topics here. Let’s start with the Ajax stuff because you know that is so hip these days. Tell us about what Prototype, Scriptaculous, and Rico are and how they are different from any of the other 20,000 Ajax frameworks out there.
| | David | Actually Prototype is kind of interesting because if you look at Struts – Struts at the beginning was this huge thing and there was a lot of good stuff in Struts that wasn’t exactly Struts-specific that got spun out into Apache Jakarta Commons. A lot of that stuff – Bean utilities and the Lang utilities and a lot of that stuff – if you look through that source code you will see author Craig McClanahan in there and a lot of that stuff was originally Struts that got spun out. Prototype is really the same thing on the Ruby side of the house. It was originally part of Rails and they spun that out into its own framework because it was a huge chunk of JavaScript that really had nothing to do with Rails Proper other than Rails used it internally. So they spun that out into its own framework. Prototype is a pretty low level framework so a bunch of frameworks have popped up on top of Prototype, such as Scriptaculous and Rico, which add much higher level things like high-level effects and drag-n-drop and things like that on top of Prototype. Good stuff. And interestingly enough, because those frameworks are just JavaScript, they are useful in the Ruby world, and they are also useful in the Java world to Java developers.
| | Kito | Okay, a lot of people that hear about JSF and maybe are working with it don’t really see how it meshes with Ajax. So if you’ve got these great JavaScript frameworks out there and you have a JSF application or are thinking about building one, how do these frameworks relate to actual JavaServer Faces development?
| | David | That’s a good question: how do you actually use these JavaScript frameworks if you are already using JSF? The answer really is that JSF is a great framework to integrate JavaScript frameworks. JSF has two things; it has a very well-defined life cycle, and it has the ability to create your own components and renderers. You can create your own components that wrap JavaScripts. In other words you can implement renderers – as you well know – that can generate JavaScripts and Ajax on the fly when they get processed in the page. Then you can add JSP tags or Facelet tags, if you prefer, on top of those components and renderers so the bottom line is that you can give page authors tags that are Ajax-enabled and they just put the tags in their pages. They don’t have to know anything about JavaScript or Ajax. They don’t even have to know what Ajax means, what it stands for. Just give them the tags and say “here’s my tags that represent Scriptaculous effects or Rico accordion components. Here’s the tags, here’s their attributes, just stick it in the page and use it.“ That encapsulation capability with components and renderers is a very compelling reason to merge JSF and Ajax together.
| | Kito | Okay so let’s say I am a JSF developer and I have decided that I see some really cool Scriptaculous effects I want to use in my application, what do I do? Is there something I can download that will help me integrate the two? Do I need to do it myself? And if so, how do I do it?
| | David | Probably right now you are going to have to do it yourself and you can do that in two ways; you can either put JavaScript directly in your views, whether that is XTML with Facelets or JSP as it normally is with JSF, or you can actually wrap that stuff in components and renderers and provide tags for those. Of course the latter – creating custom components – is a more re-usable solution because now other people can use those without having to understand the underlying JavaScript. Although, the flip side of that is that it’s a lot harder to develop components and renderers and tags that encapsulate that stuff than it is just to use the JavaScript without all that stuff. You have a choice, you can either integrate the JavaScript directly into your views and use Scriptaculous effects, or you can write a component and renderer pair that represent those effects and then give those to page authors to use with the appropriate tags.
| | Kito | What do you find people doing more often? Like when you actually do these sessions or run into people that have actually used JSF and Prototype or Scriptaculous?
| | David | It is probably about 50/50. Developing components and renderers right now in JSF with JSF 1.2, unfortunately, is not as easy as it should be. That’s one of the things we are going to be working on for JSF 2.0, undoubtedly, making it easier to create components and renderers, perhaps with a scripting language or something like that. So, there’s still a fair learning curve that people have to go through to learn how to create custom components and renderers to begin with. That is somewhat of a barrier to entry and for people that don’t want to climb that learning curve it’s much easier to just stick that JavaScript in the page and use it that way.
| | Kito | That makes a lot of sense. Just as a side note for those of you who probably don’t know this, David and I will both – unless something very strange happens – be part of the JSF 2 expert group. As part of JavaOne I am actually going to be presenting some code which will hopefully help simplify the whole component development thing. Keep your eyes out, maybe by the time this comes out there will be something a little more concrete to talk about in that area.
| | David | You will have to give me that after this interview, I would be interested to see that.
| | Kito | I will definitely tell you a little bit more about that.
| | David | Cool.
| | Kito | So moving on, we are talking about Ajax, Prototype, and Scriptaculous, you mentioned something else called Ajax4Jsf. Tell us a little more about that.
| | David | Ajax4Jsf is an awesome framework. Basically what you can do is write JavaScript by hand if you want and integrate that into JSF, kind of what we just talked about. You can also use frameworks like Prototype and Scriptaculous, which do a lot of the underlying JavaScript and use XMLHTTPRequest to do Ajax and all that, and then kind of encapsulate those details. Still in order to write JavaScript you need to understand the Prototype or Scriptaculous framework and how to use those and integrate those into you code, but with Ajax4Jsf, what that does is give you JSP tags or Facelet tags. They also have a Facelets tag lib that you can use, and basically what you do is use Facelets for JSF tags the way you would use normal JSF tags and you don’t have to write a single line of JavaScript to do an Ajax kind of thing.
For instance with Ajax4Jsf we have a couple of tags,a4j:commandButton and a4j:commandLink>, and those are replacements for the h:commandButton and h:commandLink link that you get with JSF. They are Ajax enabled so one thing you can do is you can go through your application that’s not Ajax, and you can replace your buttons and links with these Ajax enabled tags, and now you are doing Ajax with those buttons and link instead of doing a regular submit to the server and repainting the whole page when you come back. Essentially Ajax4Jsf gives you tags that you use in your views that do Ajax and you don’t have to write any JavaScript at all, you don’t have to know anything about JavaScript or Ajax or anything like that, so it’s a really natural way for JSF developers to integrate Ajax into their apps. We are already used to using tags in our views and these are just different tags that we incorporate into the page. I have found it to be really well done. The key to it is that these tags initiate a call to the server. They go through the JSF lifecycle and at the end of the lifecycle, before JSF would normally re-render the page, Ajax4Jsf just re-renders a part of your component hierarchy, you pick what components you want to re-render and it only re-renders those components. So you can set values in a backing bean, and have two components in a page that get re-rendered on the Ajax requests, and of course they would pull the updated values from the backing bean and refresh, and now you have partial refresh of the JSF component tree, which is really something – in retrospect – that we should have had to begin with but we didn’t. It’s all or nothing with JSF. If validation fails or if you return null from an action method, for instance, in JSF, nothing happens, or you repaint the entire page. This is a solution that repaints only part of the tree when you come back from your Ajax request, which is very nice. | | Editor’s note: Ajax4Jsf is now included with JBoss RichFaces (and is no longer available separately).
| | Kito | Let’s say I have a page that has some Tomahawk components on it from Apache MyFaces, or I have some validators on my pages and I don’t want to change everything to Ajax4Jsf tags, can I still use Ajax4Jsf? How does that work?
| | David | Ajax4Jsf has one tag called the support tag, and for most intents and purposes that is the workhorse of Ajax4Jsf. What you do is take that tag and put it inside your inputs and you assign an event to that tag. For instance you might assign onBlur or the onFocus event. When that event occurs, what Ajax4Jsf does is it submits the form to the server. And you also tell Ajax4Jsf what tag attributes, what components you want to re-paint when the Ajax call comes back. To summarize, what you do is take the support tag, put it inside an input and specify a JavaScript event like onBlur or onFocus or onKeyUp or onKeyDown or whatever. When that event happens, the Ajax4Jsf component submits the form, processes it on the server as JSF normally would. And then when JSF goes to repaint the page, Ajax4Jsf intercepts the life-cycle and just re-draws certain components in the tree, so it actually kind of installs itself in the life cycle. What you can do then is mix that support tag and put it in existing input tags. You can use the support tag with any input tags that you want, whether they are from a third party library or whether they are JSF standard tags or whatever. That’s only one of – I think there’re 18 Ajax4Jsf tags.
| | Kito | So it has gotten to that many?
| | David | Yeah, there are quite a few. It’s pretty robust and very well thought out and the implementation seems to be really solid.
| | Kito | Okay, it’s worthwhile to note that Ajax4Jsf -- just like Prototype, Scriptaculous, Rico -- they are all open-source projects right?
| | David | Yes they are. Ajax4Jsf was originally from Exadel. They gave it away as open-source and they had a product called RichFaces, built on top of Ajax4Jsf, and now they have given all that stuff to JBoss, which is under the RedHat umbrella. Now all that stuff is open-source. Not only Ajax4Jsf, but this RichFaces framework is now also open-source, so like many things in software – fortunately for us – everything’s free and pretty much open-source. There’re really no barriers to entry as far as price or licensing or anything like that.
| | Kito | Alright, so I think at JSFCentral we have done a decent job of talking about Facelets to some degree. Jacob Hookum, a year or two ago, did a little series for us about Facelets. It is still pretty popular among the articles on the site. For those who don’t know, Facelets is a replacement for JSP for building your JSF views. Also it takes advantage of a lot of the internals of JSF to really do it in a much more efficient way. What we really haven’t talked about too much is Seam. You said one of the things you talk about is Facelets, Seam, and Ajax4Jsf together. Tell us a little bit more about Seam and how that relates to Facelets, Ajax4Jsf, and that kind of stuff.
| | David | First of all I have read those articles that you are talking about by Jacob; they are all very well done, very well written, and of course Jacob knows what he is talking about because he is the guy that invented Facelets. Seam is… when you stop and think about it, if you are going to write a database backed application that’s a web application, nowadays if you don’t use Seam you have to use two frameworks and you have to learn how to use them together. For instance you might use Struts for the front-end and iBatis for the back-end. Or you might use JSF for the front-end and EJB3 for the back-end, or Tapestry and Hibernate. The point is you pretty much have to learn two frameworks; one for the front-end, and one for the back-end to hook up with the database. Then after you learn those two frameworks you have to learn how to integrate them together, which seems like a crazy way to have to do things. Why don’t we just have one framework that we need to learn? Then we don’t have to learn two frameworks and learn how to integrate them together. That’s really what Seam is. Seam seamlessly integrates the JSF component model and the EJB3 or Hibernate3 component models. Now we just have to have the Seam component model, and you need to learn Seam and how to use Seam components, and you are off and running.
Seam has flawless integration of the database so you basically use EJB3 or Hibernate3 and just use annotations to annotate your beans, and it’s very easy to create entity beans and session beans and stateful session beans, stateless and all that stuff. What you wind up with in the Seam application is your views, which can be either JSP or preferably Facelets, and then you have beans. You have entity beans to represent persistent data in the database. Then you can either have Java beans or stateless or stateful session beans that contain your JSF action methods. Essentially that’s all you have, beans and views. Seam collapses all the traditional layers that you have to deal with like the DTO layer and the database layer. It collapses all those down essentially into just beans and views. On the other hand, it doesn’t prevent you from having those layers. If you want to have multiple layers you can do that, but by default we just have a very simple component model where we have beans and views, and it makes development much simpler with Seam, much easier to do. In many respects Seam is Ruby [on] Rails for the Java folks, built on top of JavaServer Faces. | | Kito | One of the things that Ruby on Rails does is it has a little application – I forgot what it’s called, but basically you can point it at a database, you get some basic application, all the scaffolding you need in order to build your application. Does Seam do anything like that?
| | David | Yeah, Seam has an application called Seamgen that introspects the database, looks at your tables – very similar, by the way to what Rails does – and then can create scaffolding, essentially which is a simplistic implementation of your views. Of course that’s not meant to go into production but is meant to get you started. You can go in then and modify those views. In that respect, it is almost identical to what Rails does – that’s no coincidence. In fact, it’s my opinion that Ruby on Rails is probably one of the best things that has happened to Java because when it came out, it took the world by storm, and a lot of Java developers looked at it and said “wow, how can we get that productivity on the Java side of the house?” Fortunately for us, one of the people that looked at Rails and thought “how can we do that on the Java side of the house?” is Gavin King, who invented Hibernate. He is the guy that invented Seam, so now we really have something very comparable to Ruby on Rails on the Java side of the house that is built on top of JavaServer Faces.
| | Kito | Alright, so we talked a little bit about Prototype, Scriptaculous, Seam, Facelets. JSF 1.2 came out last year and really hasn’t had a lot of adoption so far. What are your favorite things about JSF 1.2, and what do you see as far as people using it out there?
| | David | The best thing about JSF 1.2 is the fact that now we can use JSF 1.2 and JSP 2.1 together and everything just works. That was a big sticking point with JSF 1.0 and 1.1, that mixing JSP and JSF tags didn’t always work the way people thought it should and expected it to work. Mixing HTML in was problematic, using JSTL was problematic. All of that has been ironed out now because the JSF and JSP expert groups – as you well know – got together for JSF 1.2, and now we have one expression language instead of two, and everything just works together. That really in my opinion is the main thrust behind 1.2. To be honest it’s not all that exciting.
| | Kito | Right, which is why you haven’t heard about it too much.
| | David | That’s right, JSF now has been out for three years. It came out March 2004 and here we are in May of 2007. Other than the fact that we have aligned it with JSP, we really don’t have a lot of new “gee whiz” features. Ajax has bust on the scene during that three years and we really haven’t taken advantage of that in JSF proper. Fortunately for us JSF guys, the open-source community and the commercial sector has really gotten behind JSF – because JSF is the standard web application framework – and they have kind of taken up the slack. We have Ajax4Jsf and Seam, as we have been talking about. Those guys have really stepped in and filled the void that otherwise would be there. It would be a pretty noticeable gap in JSF if there was no Ajax support available for JSF, if there was no replacement for JSP. That would stick out quite a bit.
| | Kito | Yeah me too. I think it will be a very significant release.
| | David | Absolutely.
| | Kito | Tell us about GWT, and also tell us how you see it relating to JSF.
| | David | The Google Web Toolkit? GWT is actually one of the single most exciting things I have ever seen in my software life. Essentially, as succinctly as I can put it, what GWT is, it’s Swing or AWT that runs in a browser without Webstart. That’s essentially what it is. You write all Java code, you don’t have to know anything about JavaScript, you don’t have to know anything about Ajax. You essentially just write Java code using familiar idioms that you have used in the past with AWT or SWT or Swing. For instance, if you implement event listeners, you are probably going to implement that with an anonymous inner class. If you have done Swing or AWT or SWT you know exactly what that means and know how to do it. For the most part we have four or five million developers that already intuitively know how to use this framework, they just have to learn a different API, different class names -- although interestingly enough some of the classes have the same names and the same methods as we have in AWT and Swing. It’s very easy for Java developers to learn GWT and to start creating rich Ajax-enabled user interfaces with very little learning curve to climb. That’s a really, really exciting concept. Even more exciting is that GWT has no server-side support at all, which might sound like a big drawback. Other that the fact that GWT provides a mechanism to do RPC calls to the server, once you get to the server you are entirely on your own, so if you want to integrate a database, for instance, with your GWT app, then you have to do that by hand. It sounds like a huge drawback, but actually it is part of the master plan by Google to take over the world and….The fact that there’s nothing on the server means that GWT is not going to interfere with the server-side processing that you would normally get with JSF or Struts or Tapestry or Webwork or any of that, which means that you can easily combine the two frameworks together, which is a really exciting concept. You can actually take GWT widgets and put them in your views in your Struts application or your JSF application or your Tapestry application, and you still get all the server-side processing that you get with those standard frameworks like JSF and Tapestry and Struts, but you also get Ajax-enabled widgets in your views. So you can actually combine the two together, which is a very compelling story.
| | Kito | In this interview we have talked about around twelve different ways to do Ajax, just with JSF, which is pretty amazing. I think it’s really only three or four, but that’s okay. If you were to look at GWT, under what circumstances would you want to use GWT with JSF as opposed to Ajax4Jsf with JSF, or Seam, or whatever the case may be?
| | David | It pretty much depends on your needs. If you are going to develop kind of a web 1.0 application that is essentially a series of form submits, then GWT is probably overkill and you would probably be better off using a stack of technologies like Seam, Ajax4Jsf and Facelets. On the other hand, if you want to develop applications that are truly desktop-like applications that run on a browser… So if you want, for instance, something like Swing’s viewport class that runs in a browser -- maybe you want to have a viewport and you want to have maps and multiple windows that pop up in the browser and want to be able to drag those maps around inside the viewports and resize the windows and move them around inside the browser. In other words, if you want a desktop like application that runs in the browser, that’s where GWT excels. That’s where you would want to use it. Of course if you had Legacy code… Say you have a huge Struts app: a lot of people are reluctant to say “let's just throw this Struts app out and re-write everything in GWT” – a lot of companies don’t want to take that risk. One nice thing about GWT is you can incrementally add islands of Ajax goodness in the barren landscape of your sorry-ass Struts application.
| | Kito | This is why he’s a writer.
| | David | That’s a pretty compelling argument for people that are stuck in Struts and have a lot of legacy code that they have to deal with. They can just stick GWT widgets that do awesome stuff in their views, and easily integrate that with their legacy code. Same thing for JSF. We get a lot of good stuff with JSF. We get a very well defined life-cycle. JSF takes a lot of things and does them for you, so JSF automatically validates your inputs, it converts them for you, it pushes all that stuff to the model, which is all very valuable functionality on the server side. On the client side, if you want some really cool Ajax stuff mixed in with all that server-side functionality, then you can use both GWT and JSF together and in many respects kind of get the best of both worlds.
| | Kito | Okay, sounds good. We have the wonderful outside effects of the fire engine there. So, the 2nd edition of Core JavaServer Faces is out now right?
| | David | Yeah, we just got it out. In fact we have it here at JavaOne. The shipment was actually one day late so we just got in under the wire. I saw it in the bookstore today. We cover all the new features of JSF 1.2. We added a couple of chapters on Ajax. We cover Ajax4Jsf, Seam, in fact some of the things we are talking about here are also discussed in the second edition so we are pretty excited to have it out. Unlike some other JSF book authors, we decided to actually update our book. (laughter)
| | Kito | No comment (laughing) The GWT book is going to be called what?
| | David | Its called GWT Solutions: More Cool and Useful Stuff – more because I wrote an EBook a couple of months ago called Cool and Useful Solutions – so this kind of piggybacks of that eBook.
| | Kito | So I guess the eBook did well enough to turn into a full-fledged book.
| | David | That’s what they tell me, I haven’t received my royalties for it yet. So they decided to go for the print book. I was pretty pumped about that.
| | Kito | Alright, sounds good. Last question. What was your favorite thing about the keynote today? By the way this is the first day of JavaOne so we saw the Sun keynote. David what was your favorite thing about the keynote?
| | David | It was interesting to see the Java FX scripting language, although I am not quite sure how much value that will have in the long run because it didn’t seem like it ran in the browser. We also saw some new software that runs on mobile phones, which was kind of cool. In my opinion the very best thing about the keynote was at the beginning, they had a very hot DJ that was playing the music at the beginning. It’s always fun to come to JavaOne and go to the keynote. There’s a big room with close to 10,000 people in it and you have pulsating music and a good looking DJ up there. It’s almost like going to a rock concert. You walk in there and you just get energized. It’s exciting to have Java still be around, and after 12 years still have strong attendance at JavaOne, and to be able to go in there and see light shows and dry ice coming up off the stage and loud music. It’s kind of like going to a rock concert and getting all pumped up for one more year of doing this again.
| | Kito | A good thing is this year they didn’t let Jonathan Schwartz talk that much, so I thought that was a good move on their part. (laughter)
| | David | Yeah, now that I don’t work for Sun anymore, I suppose I can agree with you there. It was not a bad keynote as far as these things go.
| | Kito | Alright David, thanks for taking the time to chat.
| | David | Thank you Kito, I appreciate it. Nice to see you again at JavaOne.
| | Kito | You too.
| | Announcer | That's it for this edition of the JSFCentral podcast.
Don’t forget, you can catch David Geary and other expert JSF speakers at JSFOne, the one event exclusively focused on the JSF Ecosystem, taking place September 4th-6th in Vienna, VA. For more info, visit www.jsfone.com. The music for this podcast was composed and performed by Kito Mann. Thank you for listening... |
|
|
|---|
| Learn how to use Facelets, an alternative to
JSP. | |
|---|
| Read about real-world JSF projects! |
|