> Date: Wed, 19 Nov 2014 17:20:00 +0700
> Subject: Re: Struts2 with AngularJS
> From: linut...@gmail.com
> To: user@struts.apache.org
>
> 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"}}
MG>Not a Struts Interceptor as Lukasz had mentioned<br>
MG>If you are absolutely convinced that you want to use Angular instead of
jquery<br>
MG>1) get Struts2-Jquery Showcase working from
https://code.google.com/p/struts2-jquery/<br>
MG>2)replace all jquery*.js with angular*.js in all of the source code<br>
MG>3)replace your default jquery library calls such as ajax calls for
$.ajax(.......) with $http.get('./struts.action');<br>
MG>the failure you are experiencing is parsing the Javascript on the client
side<br>
MG>remember to build out your struts action call and querystring before calling
$http.get<br>
MG>/struts.action?parm1=arg1,parm2=arg2<br>
MG>If on the other hand if you have struts.multipart.parser=jakarta in
struts.properties or default.properties<br>
MG>then your action is using method=POSR so call $http.post(./struts.action)
instead
MG>build out the parameters to pass in with <hidden> fields e.g. <s:hidden
name="fu" value="bar"/><br>
MG>put parameters in JSON format e.g. "string".toJSON();
MG>place JSON params into second argument to http.post e.g.
[{fu:'bar'},{fu2:'bar2'}]<br>
MG>if onsuccess method returns JSON coming back from server you can parse JSON
with data=JSON.parse(response)<br>
MG>JSON library is available in standard jquery-<version>.js<br>
MG>get yourself a browser like Chrome enable JavaScript console (CTL SHIFT J)
click on Sources pause on Caught Exceptions<br>
MG>you will see which calls are failing<br>
> 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 ?
>
> 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 ?
>
>
>
> On Wed, Nov 19, 2014 at 4:59 PM, Lukasz Lenart <lukaszlen...@apache.org>
> wrote:
>
> > 2014-11-19 9:51 GMT+01:00 foo bar <linut...@gmail.com>:
> > > 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"}}
> >
> > Maybe start with Struts AngularJS archetype first? Because it looks
> > like I you're mixing things - client side ($http) and server side
> > (interceptor)
> >
> >
> > http://struts.apache.org/release/2.3.x/docs/struts-2-maven-archetypes.html#Struts2MavenArchetypes-TheAngularJSArchetype(struts2-archetype-angularjs)
> >
> >
> > Regards
> > --
> > Łukasz
> > + 48 606 323 122 http://www.lenart.org.pl/
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> > For additional commands, e-mail: user-h...@struts.apache.org
> >
> >