struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From foo bar <linut...@gmail.com>
Subject Struts2 with AngularJS
Date Wed, 19 Nov 2014 08:51:41 GMT
Hi guys,

I'm currently looking into ease of development of using AngularJS with
Struts2.
I'm wondering what is the best practice in general
ie. AngularJS with $resource or $http, Struts2 with what plugin ?
Is the REST + convention plugin a must to support AngularJS's RESTful
nature ?

I'm currently using Struts2 with no REST plugin and notice that if I do
something like this

CustomerService.save($scope.newCustomer);

In Chrome's Developer tools, Content-Type:application/json;charset=UTF-8
and data is a JSON string but it's in the Request Payload
Normally it's Content-Type:application/x-www-form-urlencoded and data is in
Form Data

I have

private Customer customer;

in my Action class and the approriate getter and setter, but they are not
called by the framework
I understand that I can get the data via http request's inputstream, but
then I have to transfer the data to my Customer object manually (I use
Gson) and I think that will bypass all my interceptors, especially
validation.

Did a bit of research on the internet and it seems that using the REST
plugin should work, but it needs a bit of modification on the AngularJS
part ($http interceptor ?)

Struts2 won't populate my Customer object with this (which is normal plain
AngularJS)

{name:"abc",address:"abc"}

Have to change to

{customer:{name:"abc",address:"abc"}}

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message