views:

204

answers:

2

Hi. I would like to get your input on what would be the most fitting view layer for EJB 3.0 [1] Java application for me.

JSF is no good because it is a mess when it comes to web URIs. I would like a view framework which would help with automating html form submission and validation while using clean URIs like example.com/story/1 or example.com/?story=1 (using GET method).

My first guess was to go with Spring MVC. Spring is great but it feels like an overkill since JPA plus EJB already does the heavy lifting. I only need couple of things, well, four of them actually:

  1. JPA, EJB 3.0 for business layer
  2. Clean URIs: example.com/story/1 preferably
  3. HTML form helpers (validation, converters, etc)
  4. Templating similar to Apache Tiles or JSF's ui:composition

So, which one would you pick?

Ad [1]: It's used mainly for JPA and stateless/stateful local session beans

+2  A: 

My first guess was to go with Spring MVC. Spring is great but it feels like an overkill since JPA plus EJB already does the heavy lifting.

I disagree with this statement. Spring need not be an "all or none" proposition. I see nothing wrong with using Spring web MVC if that's all you need.

I'd put your EJBs and JPA behind Spring service interfaces and let the web tier deal with those, using the usual Spring idiom.

duffymo
The problem with Spring is it's configuration. When you try to bind Tiles and Spring together you get what can only be named a XML configuration hell - the URL fragments are in three, four places? Well, there's also a possibility it's just my poor understanding of Spring but... that was generally my experience while trying it out.
Michał Minicki
Annotations can help. Personally, I think the complaints about XML config are overblown. I don't know what you mean about "3 or 4" places. I think Tiles is the real issue. I prefer Sitemesh.
duffymo
Okay, I have exaggerated a little bit. It's actually two places - SimpleUrlHandlerMapping and tiles config which is pretty verbose. Enter Sitemesh. I don't know Sitemesh at all and haven't downloaded it even once - it's tutorial scared me a little. Does it do (x)html tree parsing on every call? I'm a bit afraid of possible performance hit.
Michał Minicki
+2  A: 

Apache Wicket supports RESTful URL:s out of the box using a combination of BookmarkablePageLinks and PageParameters constructor of the WebPage object. Wicket does also support Velocity templates and since it's entirely OO/POJO based it's easy to maintain in general.

Wicket fits into the Model and View parts of the MVC Model 2 and contains some samples of generic validators and specified form validators and as such it has sufficient mechanisms for supporting such features.

Esko
Wicket. Sounds... interesting. I haven't tasted (yeah, I meant tasted not tested ;) it yet. But, hey, how's its EJB3 integration? Do I get to use @EJB annotation or do I have to manually pull the beans out with JNDI calls?
Michał Minicki
Wicket's Model concept (check the IModel<T> interface at Wicket's javadoc) uses POJO's instead of EJB:s which means you don't do any kind of JNDI lookups at all because Wicket doesn't benefit from Enterprise JavaBeans in any way. Wicket is sort of bad suggestion in this case that only thing it really uses from the entire Java EE technology stack explicitly is the Servlet/Filter part in the Web Tier, everything else is POJO based. There's places where you can use annotations (like inject Spring beans directly to pages) but those aren't really related to EJB annotations.
Esko
So how exactly do you use JPA as a model and EJB as a business service with Wicket? Well, I guess I have some digging to do.
Michał Minicki
JPA really is just Hibernate in annotated mode, Wicket supports Hibernate too so using JPA shouldn't be that much of a problem.
Esko
This is what I was looking for:http://wicketstuff.org/confluence/display/STUFFWIKI/wicket-contrib-javaeeI wonder if it actually works now :)
Michał Minicki
Hey cool, I should've checked Wicketstuff myself. Note that Wicketstuff is incubator project for non-official components but there's a lot of goodies there so feel free to use that if its licensing suits you.
Esko
The wicket-javaee stuff doens't work quite as expected. It injects resources and EJB's into your wicket classes BUT (and this is a biggee) it doesn't correctly inject @Resources into the EJB's themselves.
hohonuuli