I think this is an interesting discussion. I am seeing existing Multiple Page Applications (MPA), which is Clicks forte, evolve into hybrid MPA / Single Page Applications (SPA) using frameworks like AngularJS.
For serving JSON/RPC we have been using both hand coded Servlets with net.sf.json.JSONSerializer and using services built with RESTEasy ( http://www.jboss.org/resteasy). The RESTEasy approach is more idiomatic Java (lots of layers of abstraction) and works well 99% of time. I am not sure what the value Click could provide for services. While I agree Velocity templates would be useful for rendering a JSON response, the main problem in this space is marshalling JSON request data into Java objects. Maybe Marco google library would be good for this. How would you see the services being registered, e.g. XML definition or auto-mapped some how ? regards On Wed, May 1, 2013 at 2:50 PM, Dennis M. J. Yerger < [email protected]> wrote: > Hi, Bob. What you're proposing sounds somewhat like an MVC style > application in which the proposed Service class is the controller. Your > code example reminds me of an ActionBean from the Stripes Web framework. > I'm guessing this single-page application will be driven by Ajax. If that > is the case, it is certainly possible to use ActionResults for XML/JSON > requests. I can imagine subclasses (XMLResult, JSONResult) to > conveniently convert business objects to the expected format. However, I > would add an extra lifecycle method to the Service class, onDestroy(), to > handle any necessary cleanup. > > > Date: Sat, 27 Apr 2013 15:51:00 +0200 > > From: [email protected] > > To: [email protected] > > Subject: Click Services > > > > > Hi all, > > > > With HTML5 a new breed of applications have become common, the so called > single-page apps, where the > > client side is written entirely in Javascript using jQuery, Dojo, > Mootools etc. The server is used > > to fetch data, through JSON. > > > > GWT is a possible choice for Java devs, however using Java for heavy > client side apps is a little > > clunky. Google also seems to have abandoned GWT and moved resources to > Dart. > > > > Click is mostly concerned with responding to requests with HTML code so > it isn't a good fit for > > these single-page apps. > > > > Most of these single-page apps use Rest frameworks as the backend. > > > > I've been wondering if it is worth adding a Service concept to Click > that can be used to serve up > > JSON/XML etc to single-page apps. The Service would be a first class > citizen similar to Page, but > > only with the onInit lifecycle method. Other public methods is for > handling the request eg: > > > > class MyService { > > > > public void onInit() { > > // Only lifecycle method? > > } > > > > public ActionResult getPersonData() { > > } > > > > public ActionResult savePersonData() { > > } > > } > > > > I'm not thinking of a Rest based architecture here, simply a JSON/XML > over HTTP service layer. > > > > ClickServlet might also have to be refactored into a Filter for more > flexible URL mappings. > > > > On the other hand this might just be reinventing the wheel. One thing > which would be nice with Click > > (compared to the other Rest frameworks) is our integration with Velocity. > > > > Thoughts? > > > > Kind regards > > > > Bob >
