samedi 30 mars 2013

AngularJS Trick : posting data using url form encoded


AngularJS is a great framework : really, i mean it, i havent seen such beauty in client side development for years (say Ng for friends).

It gives you a clean MVC model far superior than Backbone.js for mono page app : most of its extraordinary effectiveness comes from coding by convention pattern.

The AngularJS framework does a lot for you behind the curtain.

But yes, there is always a but somewhere,  sometimes, it does too much (I use Angular 1.0.5 for this post) .

As AngularJS afficionados say, you can use AngularJS without JQuery, it's highly recomanded they say, as JQuery can twist the new thinking you must have when using AngularJS.

I agree with most of it.

But, when dealing with one of the most trivial task in RIA development, Ng is just too opinionated.

Indeed, Ng can do some REST with ease, but it does it his way and it's quite painful when you don't know the trick to do it the way you want.

By default, Ng uses JSON to send your request data.

If your REST service does not deal with such request,  then you're dead : 500 response code you will receive.

What must we do  ?

First import JQuery in your page.

Then, You have to configure the HTTP provider for your module and transform your request data using JQuery param function, ideally in the app.js file :

Loading ....


Now, you can issue a POST request with Ng's elegant way :


Loading ....



I think it's really bad to have to use JQuery for such trivial task.

Many Ng users have complained about it, and i hope the Ng Team will fix it.

Still, AngularJS is great, long life to AngularJS !





Contrat Creative Commons
the jee architect cookbook by Olivier SCHMITT est mis à disposition selon les termes de la licence Creative Commons Paternité - Pas d'Utilisation Commerciale - Pas de Modification 3.0 Unported.


vendredi 8 mars 2013

Use Underscore.js template with JSP/JSF


Underscore.js is a great template engine, simple et efficient, easy to learn.

JSF 2 is one of the most interesting UI framework around, many powerful frameworks have been built on top of it : RichFaces, PrimeFaces, ...

Using both JSF and Underscore is a great opportunity to produce high valuable applications.

But Underscore.js use a default syntax which is not compliant with JSP/JSF compiler.

This syntax is known as ERB style, orignally designed for eRuby.

Here is a sample of this syntax :

Loading ....

JSP/JSF compiler does not taste the "<%" directive since it is a JSP directive or an invalid expression for JSF 2.

Fortunately, you can configure Underscore.js to use another syntax !

Here is new settings for Underscore.js (mustache syntax):

Loading ....

You must put this code in a JS , just before using Underscore.js.

Now, template is updated with new syntax :

Loading ....

Now, you can use Underscore in JSP or JSF 2 pages !






Contrat Creative Commons
the jee architect cookbook by Olivier SCHMITT est mis à disposition selon les termes de la licence Creative Commons Paternité - Pas d'Utilisation Commerciale - Pas de Modification 3.0 Unported.