Web2 with Java:Struts2, Spring MVC, Flex, JavaFX and Google Web Toolkit

Originally posted on the O’Reilly Books OnJava blog. 

My fellow Java Developers. Two years ago I wrote an article on ‘Web 2.0 and Enterprise Java – move over Struts‘ looking at what was likely to replace Struts 1 (then and now a de facto web standard). How did our predictions fare?

Remember that article (and this one) isn’t looking for technical best, but which is going to be a best investment of your time to learn (in a mercenary commercial sense). And if you’re deciding which to use in a project , which framework is going to be easiest to support in 5 or 10 years time?

Broadly speaking, the frameworks we talk about break into two types: those that treat the web as a set of pages, and those that treat the web as a set of components (think Visual Basic, Delphi or Oracle Forms act-a-likes).

So , what has changed in the last 2 years:

  1. The rise of Spring. Not only has it gone mainstream, but the Spring MVC, Spring Webflow and Spring-JavaServerFaces are very powerful and widely used web frameworks. A sign of how things have changed is that for Sruts 1 the Spring guys wrote the integration for the (then) bigger Struts framework. For Struts 2 , the integration was provided by the Struts community. With the forthcoming Spring 3 release the framework is increasing momentum; More annotations and less XML in Spring MVC; Rest Web Services out of the box, support for Dynamic languages like Groovy and Spring Webflow becoming a more ‘just use it where you need it’ solution.
  2. Adobe Flex and OpenLaszlo – Flash graphical interfaces on the Web, built using Java. I don’t think these will be *the* mainstream choice but I do think the will be more than a just a niche. And for design led companies, nothing else (not even Microsoft Silverlight) can come close in terms of a user ‘wow’ factor.
  3. JavaFX and Applets done right (Jim Weaver has a good article on this). More of a competitor to Adobe Flash as both are rich content in the browser using an easily obtainable plugin. JavaFX will appeal to developers because of it’s Java like syntax. I hope I’m wrong, but for rich web content, would you put your money on Sun (an Engineering led company) or Adobe (an almost apple-like design led one)?
  4. Frustration with JSF (Java Server Faces). For the last 3 years I’ve thought that ‘*this* is the year of JSF. I’m still waiting not because of lack of demand (as web apps become more complicated and use more Ajax they become more like the JSF component based model). It’s now uphill for JSF as I (and a lot of other Developers) have given up. I’m still waiting for the ‘EJB 3′ moment when JSF becomes more simple and more usable. Remember , we ‘re not talking about technically best, but which is going to be in widespread use.
  5. Google Web Toolkit (GWT). Looking at it one way , GWT is JSF done right – a component based web framework , but one that is fast and has a lot of community support. Even then it took me a long while to warm to GWT – I’ve bad memories of web-components that hide their internals (remember Microsoft Interdev 10 years ago?) . What got me over the hump was thinking of GWT as a compiler not to Assembly or bytecode , but to Javascript and HTML.

How has Struts 2 got on in the meantime? I’m not sure. Remember , Struts 2 is very different from Struts 1. Conceptually it’s very similar to Spring MVC (Simple Java Beans based with configuration); Slightly easier to learn and maybe slightly less powerful than Spring (although both are more than capable for most Enterprise web applications.

The ‘I’m not sure’ bit comes from two (non technical) factors:

  1. Struts 2 hasn’t achieved the massive Enterprise developer mind share that Struts 1 did. It’s a better framework, but it’s got more competition.
  2. If you’re using Spring in the middle tier, why not have one less framework and use Spring MVC (instead of Struts 2) in the presentation layer as well?

Back to the previous predictions , how did we get on?

Scenario 1: Adding Ajax to existing Struts Applications. Use AjaxAnywhere – closest to the approach taken in the article Sprinkle Some Ajax Magic into your Struts Web Application. Despite writing this article , I see the frameworks evolving rapidly to the point where you would only take such an approach for adding Ajax to ‘Legacy’ applications.

How did we do? I’d maybe widen the choice of Ajax Libraries (to include DWR , Dojo, Prototype and others) but the basic idea of evolving rather than replacing your Struts 1 app still holds true.

Scenario 2: Need Ajax Now for a new Java Application. Use Appfuse as it gives Struts, Ajax (with DWR) and the possiblity of JSF integration now, all ‘out of the box’.

How did we do? I still recommend AppFuse, as it combines (name-your-web-framework) with Spring Hibernate(and other ORM) and Maven. However I’d now tend towards choosing Spring MVC (unless you’ve a reason to use Spring 2), given that you’re probably already using Spring in the mid tier.

Scenario 3: Medium Term. Use an implementation of JSF (either MyFaces or whatever Appfuse promotes – probably Struts Shale). Struts Shale (JSF) has so far released only ‘overnight’ builds. Apache MyFaces (JSF) tool support and Ajax capabilities are likely to improve over time. Both Struts-Shale and MyFaces are likely to play well with AppFuse , making it a safe bet for investing your time checking it out.

How did we do? Struts2 and Spring both still give you migration route to JSF. But do you want it?

So out of the creative ajax-induced chaos of 2 years ago, I see 4 or 5 clear choices in Enterprise web frameworks: Struts 2 (as a follow on from Struts 1). Spring MVC, due to the huge mindshare Spring has on the mid-tier. Google Web Toolkit , both as a natural home of frustrated JSF developers , and because who’s going to argue with the people who gave us maps and mail? Flex, because Flash apps done well just look so good. And JavaFX, because Applets-haven’t-gone-away-you-know.

In my view, we would have been delighted to have any of these framworks 5 years ago. And each (for different reasons) is likely still to be popular in 5 years time. Your missions now is to pick the one that suits your project needs.

OpenLaszlo – Cool Flash for Clunky Java people

Flash is created by cool people who wear black and use Apple Macs. If you’re not sure as to what flash is, the chances are that if you’ve seen something on the web recently that made you go ‘wow’ for it’s coolness, then it was built using Adobe Flash.

To add substance to this froth Java people can use Flash (instead of normal web pages) to create cool pages that do useful stuff. For example Google Analytics uses Java and Flash to create a stunning User Interface. Even though Ajax and DHTML give you a lot of interactivity on your web pages, Flash goes one better at the small cost of not being as good for SEO and requiring a plugin (that most people already have installed).

So, what are you to do if you want to combine the coolness of Flash with the heavy lifting of Enterprise Java on the Server? The two main options are:

  1. Flex from Adobe is one way for Java people to create flash. The core toolkit is free, but the editor costs about $500 and that’s before you pay for using it on your servers. More details in the previous blogposts on Adobe Apollo and Adobe Flex.
  2. Open Laszlo Project is open source all the way, but does’t have a drag and drop editor (i.e. it’s more technical than graphical). Still , it allows you to create some cool effects , such as this Flash Clock.

Which framework will win out? I don’t know , and that’s before you even consider the Standard Java Web Frameworks such as Struts 2.

More (In progess) notes on Open Java and Flash are on the wiki. In an impulse buy , I bought the OpenLaszlo in Action yesterday. As an EBook , with rebate (coupon LZ35607 before the end of August) it costs about 10 Euro. Initial impressions are good (both for the book and Open Laszlo) , but I’m still working my way through it (so don’t quote me on it).

</p> <p>33</p>

Disclaimer: I get a rebate if you buy the book from Amazon, but not if you buy the (Cheaper) E-Book direct from Manning. I bought the E-Book this time, but have got free books from Manning in the past for having reviewed (as yet unpublished) JBoss items.

Moaning about Struts 1 won't help you move to Struts 2

(Struts is one of the most popular way for companies to build their websites. This was to be posted on Bill moaning about Struts 1 problems, but Bill’s blog isn’t accepting comments at the moment.)

Struts 2 Logo

Bill,

I hate to spoil your Struts 1 party , but most of these problems have been known for some time (and the Struts team would be the first to articulate them). Struts 2 is a huge improvement and , as you mention, there are good alternatives out there (including Spring MVC).

The problem is that migration from Struts 1 to (for example) Struts 2 , while easy, still carries a risk for the project in question. It can be hard to convince the business decision maker when all they see is pain (‘so you’re going to break the existing site?‘) for very little gain (‘where’s the immediate payback of upgrading?‘).

My advice is to stick with Struts 1 on existing projects. Use Struts 2 (or even better, Appfuse) on new projects. And for new code on existing projects, consider running them both side by side. They’re all tried and tested solutions.

Paul

Business Rules (Drools), Workflow (jBPM) and Seam – anybody want a training session?

Update: The presentation to the Irish Java Technologies Conference: Life and Death Workflow, using JBoss jBPM is partly based on this training session. (Link to Slides)

We’ve given Enterprise Java Training, Struts 2 Training (the most widely used Java-Web framework), and now it’s the turn of JBoss Rules (Drools) , Workflow (jBPM) and Seam. A lot of the material is coming from the forthcoming Masters Dissertation on Enterprise Web 2.0.

The course (summary below) is a private session. If there’s enough interest I’ll setup a public training session, or cut it back to 1 hour and do it as a ‘free’ intro session. If you can’t wait for that, Mark Proctor’s blog has a lot of useful rules information, and Tim Shadel has the pdf of a presentation that he gave in Phoenix Arizon on his blog.

Knowledge and Process Management

JBoss Rules, jBPM and Seam

Executive Briefing

Description: Success or failure in your business depends on dealing with information faster and better than your competitors. This briefing shows you how the JBoss Business Stack (Rules , jBPM and Seam) can do this and how to apply it to your organisation. Crucially, the briefing shows you when not to use these and details the alternative approaches.

The briefing will give delegates an overview of JBoss Rules within a web / enterprise development environment, how to architect an distribute rules within multi-tier applications and how to link these components with existing sources of information using Enterprise Application Integration (EAI).

Audience: This Briefing is suitable for IT Managers and Directors, IT project managers and technical staff who need an insight into the latest JBoss technologies and business processes, and business managers who need to be aware of the new application models and to give buy-in and commitment to applications developed within it.

Duration: Half-day

Objectives: On completion of this Briefing, delegates will:

  • Understand the benefits JBoss technologies offers your business and the key areas where it should be used.
  • Know how to successfully use JBoss Rules, jBPM and Seam with new and existing systems and technologies, including the use of Enterprise Application Integration (EAI).
  • Be able to boost projects using pre-built components and frameworks and be able to choose the right one for their needs.
  • Be aware of the main precepts of good application design within the Java component framework, as well as knowing the main Enterprise Java architecture components, terminology and acronyms and their interaction.
  • Understand how end-to-end applications are built using the JBoss frameworks (Rules, jBPM, Seam) and appreciate their organisational impact.

Presenter Biography

Paul Browne has 13 years experience delivering IT Projects in the Financial, IT/ Telecoms, Pharmaceutical and Public sectors. An author on JBoss Rules for O’Reilly Books, he has delivered courses for Limerick Institute of Technology, Siemens, Dell, Trigraph and IACT. Holding a Degree in Business from UUC, he is awaiting conferral of an Msc. in Advanced Software Engineering from UCD.

Briefing Content

Introduction and Problem Space

  • Delegate introduction
  • Trainer introduction
  • Course introduction
  • The problem we are trying to solve
  • Who is JBoss
  • 3 Tier Applications
  • What is a rule engine
  • Alternatives using Java
  • Alternatives to Rules
  • Alternative Rule Engines
  • Section Summary / Intro to next section

Rule Engine overview

    • Business Rules (examples)
    • Sample Business Uses
    • If then statements – can we do better?
    • Rete Algorithm
    • Forward and Backward Chaining
    • Domain Specific Languages (DSL)
    • Decision Tables (what the user sees)
    • Decision Tables (for the Developer)
    • Rule Editors
    • JBoss IDE (Red Hat Tools)
    • Advanced Rule Language
    • System Development Roles
    • Section Summary / Intro to next section

    Integration and Deployment

    • Web environment
    • 3 Tier system
    • Integration with Spring
    • Integration with EJB
    • What is workflow
    • What is jBPM
    • What is Seam
    • Seam and JSF
    • Seam and jBPM
    • Drools.Net
    • Section Summary
    • Course Summary and Feedback

What would you like to see on an Advanced Java Course?

Most people building systems run into the following problems again and again:

  • How to capture Business rules , in a way that both the Business users and the computer can understand.
  • How to capture the flow of actions in a system, in a way that both Business users and the computer can understand. This flow is across multiple users, and may extend over days or weeks.
  • How to deliver a system to the user (e.g. Via the Web), but to give the user a rich interface , similar to what they are used to on the desktop.
  • How to maintain and enhance older systems , now that Java has been mainstream for more than years.
  • How to take advantage of the new Features afforded by Java 5 and EJB 3, and what business problems to the solve.
  • How to build components for reuse in all environments (Web , Enterprise, Command Line and Desktop).
  • How to map information in a Java System to and from a Database (Persistent Storage or Legacy System).
  • How to deliver value to the business at every point in the project.
  • How to use the many resources and solutions already available in the Java community.

It’s to address problems like these , that I’ve been asked to put together a Advanced Java training. It’s early days yet, but I’d like to get your input as to what you’d like to see on such a course.

Java Logo
Full details of the Advanced Java course are available on the knowledgebase / Wiki. Leave your comments here.

Update: I posted a similar question on the (technical) O’Reilly Books Java blog. If you’re interested in seeing the responses , click here.

Dear Bruce Eckel : Hybrid Java, Google Web Toolkit and Adobe Flex

Dear Bruce,

First up, thanks for the book. Yes I’m saying thank-you about 8 years too late. ‘Thinking in Java‘ is what got me going in the language and in my mind is one of the best Java books written (sorry Tim). Giving it away free only cemented your reputation as the Bono of the Java world. OK, Bono without the Guitar, the Stetson and with a couple of overloaded constructors thrown in, but a man of stature nonetheless.

Thinking in Java Front Cover

Secondly, I’ll forgive your flirtations with Python, on the basis that I’ve been having an affair myself with JRuby. I now understand the pain that you’ve been having at home, the endless repetitive arguments to get simple things done, and the temptation of a newer, younger, more flexible model.

So , I think you’re onto something here in your blogpost. I can feel the pain, the need to deliver Rich clients to users over the web. I think that Ruby / Google Web Toolkit / Struts 2 / Name your web toolkit has further to go than you may think , but eventually these ‘heroic efforts‘ (nice quote) will run out of steam. On the basis of your recommendation alone I’m willing to look at Adobe Flex, but I’m not sure if this is going to solve all the problems.

Now , a lot of us Java guys don’t like change (and as if you needed proof, just look at the comments on this O’Reilly blogpost on the Google API’s). All the same , we have a problem that gets worse every passing year. 6 Years ago we could have been sure that 90% of web sites were running Internet Explorer 4. Now we’ve got IE, Firefox, Safari (in all their different versions) as well as an explosion of mobile devices. The Windows Vista launch is only going to fragment things further with yet another platform to support.

No one web solution is going to display the same in all of these browsers. We’re not going to get a single solution from Microsoft / Sun / Adobe that everybody from developer to my Granny is going to install. So we’re going to have to take the ‘least bad’ route – something that looks great, but degrades gracefully to standard HTML on less capable devices. Excuse my ignorance, but I don’t know (yet) if Flex does this.

Yes Hybridizing open source Java is the starting point for the solution. Unfortunately we’ve a long way to go yet, and Flex is perhaps only inspiration along the way.

Yours sincerely

Paul

And the results of the Virtual Java Meetup are …

And the results of the Virtual Java Meetup are … here. Names have been changed to protect the innocent.

If you couldn’t be bothered reading the entire thing , the results of the Dublin Jury on ‘what technologies should I be learning in the next 12 months’ are:

  • Web services are going to be big, but only if they can be simple.
  • EJB 3 and Netbeans are both worth taking a look at again, they are now much better than the previous versions that gave them a bad name.
  • Middleware (e.g. workflow and Rules Engines) are interesting in a corporate environment, but there is a high barrier to entry.
  • Struts , and to a lesser extent JSF , will continue to be dominant Java Web frameworks, despite not being the best technical choice.
  • A lot of companies are still using Java 1.4, but may make the leap to Java 6 (Mustang).
  • Service Orientated Architecuture (SOA) is a nice idea, but not so many projects have been implemented using it.
  • IDE’s (Netbeans / Eclipse / JDeveloper) can deliver a lot of value, but only if backed up by lower level tools (e.g. Ant and Maven).
  • More for the next 24 months , keep an eye on Apache Service Mix.