views:

215

answers:

4

JAX-RS has some MVC support, but I wonder if JAX-RS is really a good choice to build web application for human use.

If a user enters wrong or incomplete information in a form, it should be displayed again like with Grails or Wicket. Is there a comfortable way to do this with JAX-RS?

As far as I know the URI mapping doesn't work correctly, if not all required parameters are given or there are type conversion problems (with Date for example). Is that correct?

Is there support for internationalized templates?

Here is an example for a simple JAX-RS based GUI application. But it is really simple and thing like i18n and validation are not discussed.

A: 

JAX-RS is the Java EE RESTful framework. JavaServer Faces (JSF) is the Java EE MVC framework. It supports all what you've mentioned in your question: postback to same form on error, i8n/l10n and much more. To learn more about JSF, go through Java EE 6 tutorial part II chapters 4-9.

You can do a bit MVC with JAX-RS, but it isn't a full fledged MVC framework. The same story goes on that you can do a bit RESTful with JSF, but it isn't a full fledged RESTful framework.

If you want best of both worlds, I think you really need to head to Ruby on Rails or Groovy on Rails.

BalusC
Thanks. I know JSF, but I'm looking for something RESTful to build GUI apps.
deamon
Have a look for Ruby or Groovy on Rails.
BalusC
A: 

There are lots of questions in this one, I'll give my view on two of those.

"I wonder if JAX-RS is really a good choice to build web application for human use."

Web services are usually for machines to interact with, although I would argue it is usually humans that have to programme the interactions - this needs to be compared with SOAP where, at the moment, there is much more scope for machine generated code from WSDLs.

"If a user enters wrong or incomplete information in a form"

  • then in a RESTful HTTP web service which accepts a html form representation you should return HTTP error 400 because the client has provided a representation that does not conform to the representation your service expects - it is up to the client to deal with the error.
Bedwyr Humphreys
I agree with returning a 400 status when the send incorrect data. But that alone wouldn't be helpful when the data was entered in a form. It would be much better to highlight form fields.
deamon
+1  A: 

Or take the integration approach to get the best of both worlds: JAX-RS + MVC.

The JBoss RESTEasy implementation of JAX-RS integrates with Spring MVC. See http://www.jboss.org/resteasy

Here's a little tutorial on RESTEasy + Spring MVC: http://java.dzone.com/articles/resteasy-spring

marklai
Thank you for sharing the link to this interesting article!
deamon
A: 

Yes you can, but you have to clear your head of the old page-post model and start to think of your application as a disconnected UI that communicates with a RESTful SOA. When form data is entered, it post to a service endpoint if the data is not correct then you respond back with an error and the UI handles dealing with that error. You do not post forms to the server in the traditional page-post model but rather you make RPC like calls to your back end system. Your view becomes completely detached from the rest of MVC stack. This makes replacing the view with a custom mobile or IVR system extremely simple.

If a user enters wrong or incomplete information in a form, it should be displayed again like with Grails or Wicket. Is there a comfortable way to do this with JAX-RS?

With a rich internet application you do not have to repopulate data because you never left the page, an XHR call is made to the server and either a success 200 is sent back or an error. The UI then decides what to do based on that response, but the page is still intact because the call was out of band from the main UI thread.

kls
That implies the usage of JavaScript for almost all communication with the server, right?
deamon
Yes, that is one of the core concept, the server consist of two parts, the web server which provides static HTML and the application server which is a series of REST endpoints for data and business logic. From a browser you make XHR calls for getting data and for form processing, business logic. The nice part is that this gives you very fine grained control.For example you may want to validate a form after all information is entered but you may also want to check to see if a username is taken at the point that they enter it. By doing both in XHR /JAX-RS calls you have an common architecture.
kls
To clarify even thought the server consists of two parts they physically can be the same server it just helps to visualize them as two distinct entities. As well, I personal use a CMS that can export static HTML to the web server. This provides templating with no run-time dependencies. I do not use JSP but rather build the front end with pure HTML, CSS, and JavaScript.
kls