Hi Lukasz,
Yes indeed, JSON plugin is all I need, thanks !
In case anyone else experiencing the same issue, this is what I did
In AngularJS
CustomerService.save({customer:$scope.newCustomer});
You could also do
$http.post('customer/add', {customer:$scope.newCustomer}).success().error();
AngularJS will send this to the server
Content-Type:application/json;charset=UTF-8
Request Payload:{"customer":{"name":"abc","address":"abc"}}
JSON interceptor intercepts, reads data from http request inputstream,
populates Customer object in my action class
Action returns "show"
<result name="show" type="json"><param name="root">customer</param></result>
Response is {"id":1,"name":"abc","address":"abc"}
Response is read by AngularJS
If you specify <result name="show" type="json"></result>, then response
will have all your objects that have getters in your action
On Thu, Nov 20, 2014 at 4:16 PM, Lukasz Lenart <[email protected]>
wrote:
> 2014-11-19 11:20 GMT+01:00 foo bar <[email protected]>:
> > Hi,
> >
> > Thanks for the prompt reply, I'll have a look at the Struts2 AngularJS
> > archetype
> > But I meant AngularJS interceptor (
> > https://docs.angularjs.org/api/ng/service/$http) which is still client
> > side, AngularJS interceptor is meant to intercept
> {name:"abc",address:"abc"}
> > and change it to {customer:{name:"abc",address:"abc"}}
> >
> > I'm looking at the source code for the REST plugin, looks like the magic
> > happens in ContentTypeInterceptor, this gets the payload from http
> > inputstream then maps it to the action. If I want to use
> > {name:"abc",address:"abc"},
> > looks like I have to use @ModelDriven ?
>
> Yes if you want to expose customer entity and not action's properties
> (name and address)
>
> > Is it fine to just use REST plugin's ContentTypeInterceptor and the
> > JsonLibHandler and include them in my web application ?
> > i.e. are they fairly standalone-ish ? or do they have dependencies with
> > other components in the REST plugin ?
>
> Maybe JSON plugin is all you need? Then action can simply return and
> accept JSON (there is an interceptor that do all the magic)
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>