Skip to main content

If JAX-RS had an MVC framework?

Posted by lamine_ba on April 10, 2012 at 1:09 PM PDT

We build too many walls and not enough bridges.
Isaac Newton

Introduction

In my previous blog post, I have asked to many of you this question: "What JSF should become?". And since then, I was quite silent. The reason behind it, is that I was working to build a concrete implementation of this vision and today I'm glad to give you a concrete demonstration of it. So Ladies and Gentlemen, why waiting more? Let's first start with the idea you are expecting in JSF 2.2...

Multi-Templating System

In a recent interview, the JSF spec lead did talk about it and as he said this feature has gone through some iterations on the EG. And the lovely templates below are really the confirmation that a JSF developer will never build the user interface of his JSF application from scratch. He will just download a template from the web and hop he will be ready to go. And that is one reason why, I totally disagree the idea of putting the templates in a jar. Frankly, If I do so, how can I edit my templates with my cloud web-based editor or even use them remotely? And with the rise of JavaEE 7, isn't it really the time to move our IDE in the cloud?.

Templates

  1. Cartion
  2. Carligian
  3. Archange
  4. NYC
  5. Via Granitti
  6. Story of Glory
  7. Arlqueens
  8. Cimmanon
  9. Encholia
  10. Platine45

100.Jf_Texturia

YouControl

Let's come now to the interesting part of this blog post and I'm asking if it is possible to build a JSF application which does not save its state? No better, Is it possible to build a JSF application which has a lifecycle of one phase (Render Phase) and which has no <h:form> inside its views? No, Let's move the level higher, can one build a JSF application with a set of UI components that can render themselves on the client side? If your answer is no, I think it is high time for me to introduce you to my JAX-RS web application framework : YouControl....



If you have any doubt that this JSF application is in fact a JAX-RS application, just display the list of my modules and click on the wadl link to see it from yourselves.

To finish, JSF 2.0 has already a support for HTML5 and CSS3. If you put a <canvas> tag in your view, will Facelets complain or just your browser if that one does not support it? And at last, if you are wondering how my client side UI components are made, Just imagine yourself consuming your Customer service with Html 6 or Html 7 :

  1. @XmlRootElement
  2. public class Customer {
  3.  
  4.         private Long id;
  5.         private String firstName;
  6.         private String lastName;
  7.  
  8.         .......
  9. }
  1. @Path("/customers")
  2. public class CustomerService {
  3.        
  4.         @GET
  5.         @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
  6.         public List<Customer> getCustomers(){
  7.                 return dao.getCustomers();
  8.         }
  9. }
  10.  
  1. <c:table url="/customers">
  2.         <thead>
  3.               <tr>
  4.                 <th>ID</th>
  5.                 <th>First Name</th>
  6.                 <th>Last Name</th>
  7.               </tr>
  8.         </thead>
  9.         <tbody>
  10.                 <tr>
  11.                     <td> {{id}} </td>
  12.                     <td> {{firstName}} </td>
  13.                     <td> {{lastName}} </td>
  14.                 </tr>
  15.         </tbody>
  16. </c:table>
  17.  

If you are too lazy to design the table, set the auto-create attribute to true and let me do the Rest for you. Yes, Ladies and Gentlemen, Javascript, Json and client-side templating systems like Mustache are really awesome....

  1. <c:table url="/customers" auto-create="true"/>

I sincerely hope that at this moment, the JSF guys are asking really this question : Hey wait a minute, where is my Managed Bean?. ( #{customerBean.customer.id}, #{customerBean.customer.firstName}, #{customerBean.customer.lastName}. ..)



twitter : lamine_ba

 

AttachmentSize
editor.PNG85.85 KB
modules.PNG39.93 KB

Comments

Hello Lamine, I tried the Facelets / JAX-RS approach you ...

Hello Lamine,

I tried the Facelets / JAX-RS approach you demonstrated.

Really nice, but I'm not sure of its interest (or any other server-side templating engine) now that you have client side frameworks like AngularJS - which give you the same (and more) functionnalities than facelets / jsf but client side.

You just need to create you JAX-RS service, and develop your client side application with html fragments, angularJs and some js widgets (jquery UI or Prime UI).

Perhaps I'm missing sthg ? If this is the case, thanks for indicating what's missing ;)

links :
* http://statelessprime.blogspot.fr/2012/12/goal1-integrate-primeui-with-a...
* the excellent tutorial from angularJS http://docs.angularjs.org/tutorial/

Hi Gonzalad, First of all, Thank you very ...

Hi Gonzalad,

First of all, Thank you very much for your great comment
and for having shared with me your great post which I had the chance and the pleasure to read a long time before.

1) http://statelessprime.blogspot.fr/2012/12/goal1-integrate-primeui-with-a...

You and I, we are promoting the same approach : Client-Side (JQuery, PrimeUI, ..) + Server-Side (JAX-RS). But you have to admit that the client-side cannot yet give you the ability to change the look and feel of your web application at runtime? How one will implement my multi-templating system on the client-side?

1) http://youcontrol.lamine.cloudbees.net/faces/index.xhtml?template=cartion

2) http://youcontrol.lamine.cloudbees.net/faces/index.xhtml?template=archan...

I'm currently building a generic and modular web framework client-side oriented that could be the foundation of a Cloud IDE. And there is nothing stopping you from using angular.js, backbone.js, PrimeUI or whatever, such I'm doing, to create your own module without using the approach that I have promoted in my blog post. In fact, you can use it only if you have my tiny runtime which will help you to write your JAX-RS web services with Groovy, Scala and such...

3) http://youcontrol.lamine.cloudbees.net/faces/admin/modules/edit.xhtml?id...

But along the way, I have learned this : we are not all fluent in JavaScript. So there is still some people who need to have some abstractions. and without the concept of a UI Component, I can assure you that we are just coming back to the road of duplication. To integrate my cloud editor into your application, Are you ready to rewrite its markup and reference its dependencies in all of your web pages? or will you just give the name of your folder and let me do the REST for you?

<c:fileEditor folder="myFolder"/>

Before reading this, please read my response to your ...

Before reading this, please read my response to your 20111127 post.

Hello Lamine, thanks for this nice blog post.  You say,

> That is one reason why, I totally disagree the idea of putting the
> templates in a jar. Frankly, If I do so, how can I edit my templates
> with my cloud web-based editor?

Putting templates in a jar is a deploypment time expedient.  The idea is
for templates to be hosted in a maven repo.  If you want to edit them,
you'd have to manually download it and bundle it into your app, or you
could re-package it as a jar and consume it that way.

Regarding YouControl, I agree with Cay, keep at it!  I hope you find a
productive partnership coming from this work.

Thanks,

Ed

Hello, Ed Thanks for your nice comment. Yes I know, I ...

Hello, Ed

Thanks for your nice comment. Yes I know, I was very radical in my statement but it was just a way to show to the JSF users, the opposite face of the vision you have. In fact what you have read is just a projection of a near future from my perspective. So the key thing is to design the Multi-Templating feature abstract enough to let the conflicting visions to coexist......

Regarding YouControl, Yes I will keep at it while hoping to have a
productive partnership soon.

Thanks,

Lamine

This definitely an interesting way to go. I'll definitely ...

This definitely an interesting way to go. I'll definitely take a look at it.

Ivan

Hi, I am glad you are thinking along these lines. I just had ...

Hi, I am glad you are thinking along these lines. I just had to make a service accessible to people, and I thought, heck, I just use JAX-RS and some forgettable UI. Much to my surprise, that was a smart move. Yes, I want to go the next step with JSF to use a pretty UI, but I also don't want to lose the benefits of a service-oriented interface. Keep at it!

Hi Cay, Thank you very much for your comment. It has set ...

Hi Cay, Thank you very much for your comment. It has set up the real vision which is to replace the programming model of JSF by that of JAX-RS while keeping all the parts related to the UI that JSF did right (Composite components, Facelets Templating,...).

By the way, Core Javaserver Faces is one the book where I have learned JSF. My sincere congratulations for all the good things in it....

Thanks,
Lamine