You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jane Wayne <ja...@gmail.com> on 2012/10/05 00:21:32 UTC

how to write json/xml output using struts 2 and rest + convention plugin

i've downloaded the demo apps for struts 2 v2.3.5 SNAPSHOT for today.
i am trying to understand and study the rest struts2-rest-showcase
webapp.

in the rest showcase, the OrdersController class has the following method.

public String editNew() {
 model = new Order();
 return "editNew";
}

the user is taken to orders-editNew.jsp. on this page, the form posts
to: action="%{#request.contextPath}/orders". the action to handle this
form is as follows.

public HttpHeaders create() {
 ordersService.save(model);
 addActionMessage("New order created successfully");
 return new DefaultHttpHeaders("success").setLocationId(model.getId());
}

at this point, the user is taken to orders-index.jsp. however, i do
not want to take the user to this page. i instead want to write a
JSON/XML message back saying something (just like the action message)
to indicate success/failure. how do i do this?

i imagine my client application posting data to: /orders/new
and then receiving some JSON message:
{ "results" : "New order created successfully" }

any help is appreciated.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: how to write json/xml output using struts 2 and rest + convention plugin

Posted by Frans Thamura <fr...@meruvian.org>.
may be for full rest showcase

you can checkout from our svn in yama.java.net

full crud, bootstrap and spring hibernate. coee of our nurdoo.org

you can take alook our rest security implementation also there

feedback welcome for all

Frans Thamura
Meruvian
On Oct 5, 2012 9:03 PM, "Jane Wayne" <ja...@gmail.com> wrote:

> yes, somewhat (not xml, but json). i modified the rest showcase. in
> particular, i modified, orders-editNew.jsp. i modified the form the
> look like this:
>
> <s:form method="post" action="%{#request.contextPath}/orders.json">
>
> the original line was:
>
> <s:form method="post" action="%{#request.contextPath}/orders">
>
> i believe the place to return XML/JSON is in the method create().
>
>     // POST /orders
>     public HttpHeaders create() {
>         ordersService.save(model);
>         addActionMessage("New order created successfully");
>         return new DefaultHttpHeaders("success")
>             .setLocationId(model.getId());
>     }
>
> this method returns a new HttpHeaders object signalling "success", and
> in this showcase, "success" gets map back to index() which is GET
> /orders (shows all the orders). but these are not response output (as
> in request/response).
>
> the struts2-rest-plugin tutorial goes to explain the mapping of GET,
> POST, PUT, DELETE to default controller methods
> (http://struts.apache.org/2.x/docs/rest-plugin.html). however, it is
> not clear to me, what i can return for the method. in fact, it seems
> that a result of type HttpHeaders or String can be returned (the
> difference is explained, and very helpful).
>
> when i used the struts2-json-plugin, all i remember doing was adding
> @ParentPackage(value="json-default") to the action class + adding
> @Action { ... @Result(...,type="json",params={"root","myPojo"}) } to
> the method. automagically, myPojo was serialized to JSON.
>
> i'm wondering if it's even possible to do the same with struts2 +
> convention + rest ?
>
> before using the struts2-json-plugin, my action would extend
> ActionSupport and implement ServletRequestAware and
> ServletResponseAware. i would then simply use ServletOutputStream to
> write the JSON/XML stuff directly. it's not elegant, but i might
> kludge an approach like this one.
>
> On Fri, Oct 5, 2012 at 8:22 AM, Lukasz Lenart <lu...@apache.org>
> wrote:
> > 2012/10/5 Jane Wayne <ja...@gmail.com>:
> >> not really/entirely what i'm looking for. the struts2-json-plugin
> >> supports json. but what about xml? i need the flexibility to alter
> >> between the two for the client/consumer of the rest services.
> >
> > Did you try to add .xml suffix to request action ?
> >
> >
> > Regards
> >
> > --
> > Łukasz
> > + 48 606 323 122 http://www.lenart.org.pl/
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: how to write json/xml output using struts 2 and rest + convention plugin

Posted by Jane Wayne <ja...@gmail.com>.
yes, somewhat (not xml, but json). i modified the rest showcase. in
particular, i modified, orders-editNew.jsp. i modified the form the
look like this:

<s:form method="post" action="%{#request.contextPath}/orders.json">

the original line was:

<s:form method="post" action="%{#request.contextPath}/orders">

i believe the place to return XML/JSON is in the method create().

    // POST /orders
    public HttpHeaders create() {
        ordersService.save(model);
        addActionMessage("New order created successfully");
        return new DefaultHttpHeaders("success")
            .setLocationId(model.getId());
    }

this method returns a new HttpHeaders object signalling "success", and
in this showcase, "success" gets map back to index() which is GET
/orders (shows all the orders). but these are not response output (as
in request/response).

the struts2-rest-plugin tutorial goes to explain the mapping of GET,
POST, PUT, DELETE to default controller methods
(http://struts.apache.org/2.x/docs/rest-plugin.html). however, it is
not clear to me, what i can return for the method. in fact, it seems
that a result of type HttpHeaders or String can be returned (the
difference is explained, and very helpful).

when i used the struts2-json-plugin, all i remember doing was adding
@ParentPackage(value="json-default") to the action class + adding
@Action { ... @Result(...,type="json",params={"root","myPojo"}) } to
the method. automagically, myPojo was serialized to JSON.

i'm wondering if it's even possible to do the same with struts2 +
convention + rest ?

before using the struts2-json-plugin, my action would extend
ActionSupport and implement ServletRequestAware and
ServletResponseAware. i would then simply use ServletOutputStream to
write the JSON/XML stuff directly. it's not elegant, but i might
kludge an approach like this one.

On Fri, Oct 5, 2012 at 8:22 AM, Lukasz Lenart <lu...@apache.org> wrote:
> 2012/10/5 Jane Wayne <ja...@gmail.com>:
>> not really/entirely what i'm looking for. the struts2-json-plugin
>> supports json. but what about xml? i need the flexibility to alter
>> between the two for the client/consumer of the rest services.
>
> Did you try to add .xml suffix to request action ?
>
>
> Regards
>
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: how to write json/xml output using struts 2 and rest + convention plugin

Posted by Lukasz Lenart <lu...@apache.org>.
2012/10/5 Jane Wayne <ja...@gmail.com>:
> not really/entirely what i'm looking for. the struts2-json-plugin
> supports json. but what about xml? i need the flexibility to alter
> between the two for the client/consumer of the rest services.

Did you try to add .xml suffix to request action ?


Regards

-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: how to write json/xml output using struts 2 and rest + convention plugin

Posted by Frans Thamura <fr...@meruvian.org>.
we now use mostly @action and @result as struts.xml replacement.

Frans Thamura
Meruvian
On Oct 5, 2012 7:25 PM, "Lukasz Lenart" <lu...@apache.org> wrote:

> 2012/10/5 Frans Thamura <fr...@meruvian.org>:
> > hi jane
> >
> > all our apps using s2 with rest and json.
> >
> > see our example.at www.nurdoo.org
>
> Yep, exactly, try urls like below
>
> http://www.nurdoo.org/module/prayers
> http://www.nurdoo.org/module/prayers.json
> http://www.nurdoo.org/module/prayers.xml
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: how to write json/xml output using struts 2 and rest + convention plugin

Posted by Lukasz Lenart <lu...@apache.org>.
2012/10/5 Frans Thamura <fr...@meruvian.org>:
> hi jane
>
> all our apps using s2 with rest and json.
>
> see our example.at www.nurdoo.org

Yep, exactly, try urls like below

http://www.nurdoo.org/module/prayers
http://www.nurdoo.org/module/prayers.json
http://www.nurdoo.org/module/prayers.xml


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: how to write json/xml output using struts 2 and rest + convention plugin

Posted by Jane Wayne <ja...@gmail.com>.
1. looks interesting. could you show an example or do you have one
illustrating how to write JSON back?

2. i'm not sure what to do with the online app?

On Fri, Oct 5, 2012 at 12:45 PM, Frans Thamura <fr...@meruvian.org> wrote:
> hi all esp jane
>
> let me summarize all our work here.
>
> 1. S2 REST Plugins
>
> we modify the default S2 REST Plugin, so we dont need SMD anymore,
> just use @Action and @Resut with type, and you can get full REST ,
> PUT, GET, DELETE, POST.
>
> @Action(name = "/list", method = HttpMethod.GET) -> for REST GET
>
> take a look the plugins.
>
> http://java.net/projects/s2restplugins/pages/Home
>
> 2. Yama
> We use S2 + REST plugin (no. 1 above), and use Spring + Hibernate, call it Yama.
>
> http://yama.java.net/
>
> this is a project template to start create a CRUD using S2 with REST
> approach, output can JSON or XML.
>
> see my yama run on Azure. http://yama7.cloudapp.net/yama/
>
> and our yama-showcase also in the SVN, and this is the demo. run on
> Stackato (OpenSTack and Cloud Foundry integration ).
> http://yama-showcases.atisicloud.net/home
>
> user admin, password admin.
>
> the key in yama, is DefaultPersistance and several "aware" , take a
> look inside Spring Context to understand it.
>
> 3. Nurdoo
> We create nurdoo , as a real case implementation using yama.
>
>
> all opensourced under Apache license. enjoy. we create a lot of apps
> based on yama.
>
>
> --
> Frans Thamura (曽志胜)
> Shadow Master and Lead Investor
> Meruvian.
> Integrated Hypermedia Java Solution Provider.
>
> Mobile: +628557888699
> Blog: http://blogs.mervpolis.com/roller/flatburger (id)
>
> FB: http://www.facebook.com/meruvian
> TW: http://www.twitter.com/meruvian / @meruvian
> Website: http://www.meruvian.org
>
> "We grow because we share the same belief."
>
>
> On Fri, Oct 5, 2012 at 9:19 PM, Frans Thamura <fr...@meruvian.org> wrote:
>> jane
>>
>> the way our rest model is not using smd which you can get in s2 default rest
>> plugins
>>
>> please visit our s2restplugins.java.net
>>
>> may be this plugins and small wiki can explain more.
>>
>> the category has extended from default persistanc. you must see the spring
>> injection that handle this
>>
>> Frans Thamura
>> Meruvian
>>
>> On Oct 5, 2012 9:13 PM, "Jane Wayne" <ja...@gmail.com> wrote:
>>>
>>> frans,
>>>
>>> i'm looking at
>>> http://java.net/projects/nurdoo/sources/nurdoo-web-svn/content/trunk/src/main/java/org/nurdoo/prayers/actions/CategoryAction.java?rev=3.
>>>
>>> could you please point me specifically to how you guys output JSON/XML
>>> back to the client?
>>>
>>> let me see if i got this right. you guys use s2 + rest + convention to
>>> accomplish the restful features. then, you guys used freemarker to
>>> output content? where's the code/ability to swap between JSON/XML for
>>> output?
>>>
>>> On Fri, Oct 5, 2012 at 8:22 AM, Frans Thamura <fr...@meruvian.org> wrote:
>>> > hi jane
>>> >
>>> > all our apps using s2 with rest and json.
>>> >
>>> > see our example.at www.nurdoo.org
>>> >
>>> > source in nurdoo.java.net
>>> >
>>> > Frans Thamura
>>> > Meruvian
>>> > On Oct 5, 2012 7:11 PM, "Jane Wayne" <ja...@gmail.com> wrote:
>>> >
>>> >> not really/entirely what i'm looking for. the struts2-json-plugin
>>> >> supports json. but what about xml? i need the flexibility to alter
>>> >> between the two for the client/consumer of the rest services.
>>> >>
>>> >> On Thu, Oct 4, 2012 at 7:41 PM, Ken McWilliams
>>> >> <ke...@gmail.com>
>>> >> wrote:
>>> >> > I'm not familiar with this application but simply look at the
>>> >> > documentation for the struts2-json-plugin, you can specify a json
>>> >> > result and you can specify include and exclude parameters (so you
>>> >> > just
>>> >> > return the part(s) of your Action you want). In this way you could
>>> >> > define a new map, put a key of "results" with a value of "New order
>>> >> > created successfully" and return it quite easily. If the struts2
>>> >> > document is insufficient there are plenty of examples also on
>>> >> > StackOverflow, so take a look there too (Including many annotation
>>> >> > based examples).
>>> >> >
>>> >> > On Thu, Oct 4, 2012 at 4:21 PM, Jane Wayne <ja...@gmail.com>
>>> >> wrote:
>>> >> >> i've downloaded the demo apps for struts 2 v2.3.5 SNAPSHOT for
>>> >> >> today.
>>> >> >> i am trying to understand and study the rest struts2-rest-showcase
>>> >> >> webapp.
>>> >> >>
>>> >> >> in the rest showcase, the OrdersController class has the following
>>> >> method.
>>> >> >>
>>> >> >> public String editNew() {
>>> >> >>  model = new Order();
>>> >> >>  return "editNew";
>>> >> >> }
>>> >> >>
>>> >> >> the user is taken to orders-editNew.jsp. on this page, the form
>>> >> >> posts
>>> >> >> to: action="%{#request.contextPath}/orders". the action to handle
>>> >> >> this
>>> >> >> form is as follows.
>>> >> >>
>>> >> >> public HttpHeaders create() {
>>> >> >>  ordersService.save(model);
>>> >> >>  addActionMessage("New order created successfully");
>>> >> >>  return new
>>> >> >> DefaultHttpHeaders("success").setLocationId(model.getId());
>>> >> >> }
>>> >> >>
>>> >> >> at this point, the user is taken to orders-index.jsp. however, i do
>>> >> >> not want to take the user to this page. i instead want to write a
>>> >> >> JSON/XML message back saying something (just like the action
>>> >> >> message)
>>> >> >> to indicate success/failure. how do i do this?
>>> >> >>
>>> >> >> i imagine my client application posting data to: /orders/new
>>> >> >> and then receiving some JSON message:
>>> >> >> { "results" : "New order created successfully" }
>>> >> >>
>>> >> >> any help is appreciated.
>>> >> >>
>>> >> >>
>>> >> >> ---------------------------------------------------------------------
>>> >> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> >> >> For additional commands, e-mail: user-help@struts.apache.org
>>> >> >>
>>> >> >
>>> >> > ---------------------------------------------------------------------
>>> >> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> >> > For additional commands, e-mail: user-help@struts.apache.org
>>> >> >
>>> >>
>>> >> ---------------------------------------------------------------------
>>> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> >> For additional commands, e-mail: user-help@struts.apache.org
>>> >>
>>> >>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: how to write json/xml output using struts 2 and rest + convention plugin

Posted by Frans Thamura <fr...@meruvian.org>.
hi all esp jane

let me summarize all our work here.

1. S2 REST Plugins

we modify the default S2 REST Plugin, so we dont need SMD anymore,
just use @Action and @Resut with type, and you can get full REST ,
PUT, GET, DELETE, POST.

@Action(name = "/list", method = HttpMethod.GET) -> for REST GET

take a look the plugins.

http://java.net/projects/s2restplugins/pages/Home

2. Yama
We use S2 + REST plugin (no. 1 above), and use Spring + Hibernate, call it Yama.

http://yama.java.net/

this is a project template to start create a CRUD using S2 with REST
approach, output can JSON or XML.

see my yama run on Azure. http://yama7.cloudapp.net/yama/

and our yama-showcase also in the SVN, and this is the demo. run on
Stackato (OpenSTack and Cloud Foundry integration ).
http://yama-showcases.atisicloud.net/home

user admin, password admin.

the key in yama, is DefaultPersistance and several "aware" , take a
look inside Spring Context to understand it.

3. Nurdoo
We create nurdoo , as a real case implementation using yama.


all opensourced under Apache license. enjoy. we create a lot of apps
based on yama.


--
Frans Thamura (曽志胜)
Shadow Master and Lead Investor
Meruvian.
Integrated Hypermedia Java Solution Provider.

Mobile: +628557888699
Blog: http://blogs.mervpolis.com/roller/flatburger (id)

FB: http://www.facebook.com/meruvian
TW: http://www.twitter.com/meruvian / @meruvian
Website: http://www.meruvian.org

"We grow because we share the same belief."


On Fri, Oct 5, 2012 at 9:19 PM, Frans Thamura <fr...@meruvian.org> wrote:
> jane
>
> the way our rest model is not using smd which you can get in s2 default rest
> plugins
>
> please visit our s2restplugins.java.net
>
> may be this plugins and small wiki can explain more.
>
> the category has extended from default persistanc. you must see the spring
> injection that handle this
>
> Frans Thamura
> Meruvian
>
> On Oct 5, 2012 9:13 PM, "Jane Wayne" <ja...@gmail.com> wrote:
>>
>> frans,
>>
>> i'm looking at
>> http://java.net/projects/nurdoo/sources/nurdoo-web-svn/content/trunk/src/main/java/org/nurdoo/prayers/actions/CategoryAction.java?rev=3.
>>
>> could you please point me specifically to how you guys output JSON/XML
>> back to the client?
>>
>> let me see if i got this right. you guys use s2 + rest + convention to
>> accomplish the restful features. then, you guys used freemarker to
>> output content? where's the code/ability to swap between JSON/XML for
>> output?
>>
>> On Fri, Oct 5, 2012 at 8:22 AM, Frans Thamura <fr...@meruvian.org> wrote:
>> > hi jane
>> >
>> > all our apps using s2 with rest and json.
>> >
>> > see our example.at www.nurdoo.org
>> >
>> > source in nurdoo.java.net
>> >
>> > Frans Thamura
>> > Meruvian
>> > On Oct 5, 2012 7:11 PM, "Jane Wayne" <ja...@gmail.com> wrote:
>> >
>> >> not really/entirely what i'm looking for. the struts2-json-plugin
>> >> supports json. but what about xml? i need the flexibility to alter
>> >> between the two for the client/consumer of the rest services.
>> >>
>> >> On Thu, Oct 4, 2012 at 7:41 PM, Ken McWilliams
>> >> <ke...@gmail.com>
>> >> wrote:
>> >> > I'm not familiar with this application but simply look at the
>> >> > documentation for the struts2-json-plugin, you can specify a json
>> >> > result and you can specify include and exclude parameters (so you
>> >> > just
>> >> > return the part(s) of your Action you want). In this way you could
>> >> > define a new map, put a key of "results" with a value of "New order
>> >> > created successfully" and return it quite easily. If the struts2
>> >> > document is insufficient there are plenty of examples also on
>> >> > StackOverflow, so take a look there too (Including many annotation
>> >> > based examples).
>> >> >
>> >> > On Thu, Oct 4, 2012 at 4:21 PM, Jane Wayne <ja...@gmail.com>
>> >> wrote:
>> >> >> i've downloaded the demo apps for struts 2 v2.3.5 SNAPSHOT for
>> >> >> today.
>> >> >> i am trying to understand and study the rest struts2-rest-showcase
>> >> >> webapp.
>> >> >>
>> >> >> in the rest showcase, the OrdersController class has the following
>> >> method.
>> >> >>
>> >> >> public String editNew() {
>> >> >>  model = new Order();
>> >> >>  return "editNew";
>> >> >> }
>> >> >>
>> >> >> the user is taken to orders-editNew.jsp. on this page, the form
>> >> >> posts
>> >> >> to: action="%{#request.contextPath}/orders". the action to handle
>> >> >> this
>> >> >> form is as follows.
>> >> >>
>> >> >> public HttpHeaders create() {
>> >> >>  ordersService.save(model);
>> >> >>  addActionMessage("New order created successfully");
>> >> >>  return new
>> >> >> DefaultHttpHeaders("success").setLocationId(model.getId());
>> >> >> }
>> >> >>
>> >> >> at this point, the user is taken to orders-index.jsp. however, i do
>> >> >> not want to take the user to this page. i instead want to write a
>> >> >> JSON/XML message back saying something (just like the action
>> >> >> message)
>> >> >> to indicate success/failure. how do i do this?
>> >> >>
>> >> >> i imagine my client application posting data to: /orders/new
>> >> >> and then receiving some JSON message:
>> >> >> { "results" : "New order created successfully" }
>> >> >>
>> >> >> any help is appreciated.
>> >> >>
>> >> >>
>> >> >> ---------------------------------------------------------------------
>> >> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> >> >> For additional commands, e-mail: user-help@struts.apache.org
>> >> >>
>> >> >
>> >> > ---------------------------------------------------------------------
>> >> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> >> > For additional commands, e-mail: user-help@struts.apache.org
>> >> >
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> >> For additional commands, e-mail: user-help@struts.apache.org
>> >>
>> >>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: how to write json/xml output using struts 2 and rest + convention plugin

Posted by Frans Thamura <fr...@meruvian.org>.
jane

the way our rest model is not using smd which you can get in s2 default
rest plugins

please visit our s2restplugins.java.net

may be this plugins and small wiki can explain more.

the category has extended from default persistanc. you must see the spring
injection that handle this

Frans Thamura
Meruvian
On Oct 5, 2012 9:13 PM, "Jane Wayne" <ja...@gmail.com> wrote:

> frans,
>
> i'm looking at
> http://java.net/projects/nurdoo/sources/nurdoo-web-svn/content/trunk/src/main/java/org/nurdoo/prayers/actions/CategoryAction.java?rev=3
> .
>
> could you please point me specifically to how you guys output JSON/XML
> back to the client?
>
> let me see if i got this right. you guys use s2 + rest + convention to
> accomplish the restful features. then, you guys used freemarker to
> output content? where's the code/ability to swap between JSON/XML for
> output?
>
> On Fri, Oct 5, 2012 at 8:22 AM, Frans Thamura <fr...@meruvian.org> wrote:
> > hi jane
> >
> > all our apps using s2 with rest and json.
> >
> > see our example.at www.nurdoo.org
> >
> > source in nurdoo.java.net
> >
> > Frans Thamura
> > Meruvian
> > On Oct 5, 2012 7:11 PM, "Jane Wayne" <ja...@gmail.com> wrote:
> >
> >> not really/entirely what i'm looking for. the struts2-json-plugin
> >> supports json. but what about xml? i need the flexibility to alter
> >> between the two for the client/consumer of the rest services.
> >>
> >> On Thu, Oct 4, 2012 at 7:41 PM, Ken McWilliams <
> ken.mcwilliams@gmail.com>
> >> wrote:
> >> > I'm not familiar with this application but simply look at the
> >> > documentation for the struts2-json-plugin, you can specify a json
> >> > result and you can specify include and exclude parameters (so you just
> >> > return the part(s) of your Action you want). In this way you could
> >> > define a new map, put a key of "results" with a value of "New order
> >> > created successfully" and return it quite easily. If the struts2
> >> > document is insufficient there are plenty of examples also on
> >> > StackOverflow, so take a look there too (Including many annotation
> >> > based examples).
> >> >
> >> > On Thu, Oct 4, 2012 at 4:21 PM, Jane Wayne <ja...@gmail.com>
> >> wrote:
> >> >> i've downloaded the demo apps for struts 2 v2.3.5 SNAPSHOT for today.
> >> >> i am trying to understand and study the rest struts2-rest-showcase
> >> >> webapp.
> >> >>
> >> >> in the rest showcase, the OrdersController class has the following
> >> method.
> >> >>
> >> >> public String editNew() {
> >> >>  model = new Order();
> >> >>  return "editNew";
> >> >> }
> >> >>
> >> >> the user is taken to orders-editNew.jsp. on this page, the form posts
> >> >> to: action="%{#request.contextPath}/orders". the action to handle
> this
> >> >> form is as follows.
> >> >>
> >> >> public HttpHeaders create() {
> >> >>  ordersService.save(model);
> >> >>  addActionMessage("New order created successfully");
> >> >>  return new
> DefaultHttpHeaders("success").setLocationId(model.getId());
> >> >> }
> >> >>
> >> >> at this point, the user is taken to orders-index.jsp. however, i do
> >> >> not want to take the user to this page. i instead want to write a
> >> >> JSON/XML message back saying something (just like the action message)
> >> >> to indicate success/failure. how do i do this?
> >> >>
> >> >> i imagine my client application posting data to: /orders/new
> >> >> and then receiving some JSON message:
> >> >> { "results" : "New order created successfully" }
> >> >>
> >> >> any help is appreciated.
> >> >>
> >> >> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> >> For additional commands, e-mail: user-help@struts.apache.org
> >> >>
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> > For additional commands, e-mail: user-help@struts.apache.org
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: how to write json/xml output using struts 2 and rest + convention plugin

Posted by Jane Wayne <ja...@gmail.com>.
frans,

i'm looking at http://java.net/projects/nurdoo/sources/nurdoo-web-svn/content/trunk/src/main/java/org/nurdoo/prayers/actions/CategoryAction.java?rev=3.

could you please point me specifically to how you guys output JSON/XML
back to the client?

let me see if i got this right. you guys use s2 + rest + convention to
accomplish the restful features. then, you guys used freemarker to
output content? where's the code/ability to swap between JSON/XML for
output?

On Fri, Oct 5, 2012 at 8:22 AM, Frans Thamura <fr...@meruvian.org> wrote:
> hi jane
>
> all our apps using s2 with rest and json.
>
> see our example.at www.nurdoo.org
>
> source in nurdoo.java.net
>
> Frans Thamura
> Meruvian
> On Oct 5, 2012 7:11 PM, "Jane Wayne" <ja...@gmail.com> wrote:
>
>> not really/entirely what i'm looking for. the struts2-json-plugin
>> supports json. but what about xml? i need the flexibility to alter
>> between the two for the client/consumer of the rest services.
>>
>> On Thu, Oct 4, 2012 at 7:41 PM, Ken McWilliams <ke...@gmail.com>
>> wrote:
>> > I'm not familiar with this application but simply look at the
>> > documentation for the struts2-json-plugin, you can specify a json
>> > result and you can specify include and exclude parameters (so you just
>> > return the part(s) of your Action you want). In this way you could
>> > define a new map, put a key of "results" with a value of "New order
>> > created successfully" and return it quite easily. If the struts2
>> > document is insufficient there are plenty of examples also on
>> > StackOverflow, so take a look there too (Including many annotation
>> > based examples).
>> >
>> > On Thu, Oct 4, 2012 at 4:21 PM, Jane Wayne <ja...@gmail.com>
>> wrote:
>> >> i've downloaded the demo apps for struts 2 v2.3.5 SNAPSHOT for today.
>> >> i am trying to understand and study the rest struts2-rest-showcase
>> >> webapp.
>> >>
>> >> in the rest showcase, the OrdersController class has the following
>> method.
>> >>
>> >> public String editNew() {
>> >>  model = new Order();
>> >>  return "editNew";
>> >> }
>> >>
>> >> the user is taken to orders-editNew.jsp. on this page, the form posts
>> >> to: action="%{#request.contextPath}/orders". the action to handle this
>> >> form is as follows.
>> >>
>> >> public HttpHeaders create() {
>> >>  ordersService.save(model);
>> >>  addActionMessage("New order created successfully");
>> >>  return new DefaultHttpHeaders("success").setLocationId(model.getId());
>> >> }
>> >>
>> >> at this point, the user is taken to orders-index.jsp. however, i do
>> >> not want to take the user to this page. i instead want to write a
>> >> JSON/XML message back saying something (just like the action message)
>> >> to indicate success/failure. how do i do this?
>> >>
>> >> i imagine my client application posting data to: /orders/new
>> >> and then receiving some JSON message:
>> >> { "results" : "New order created successfully" }
>> >>
>> >> any help is appreciated.
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> >> For additional commands, e-mail: user-help@struts.apache.org
>> >>
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> > For additional commands, e-mail: user-help@struts.apache.org
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: how to write json/xml output using struts 2 and rest + convention plugin

Posted by Frans Thamura <fr...@meruvian.org>.
hi jane

all our apps using s2 with rest and json.

see our example.at www.nurdoo.org

source in nurdoo.java.net

Frans Thamura
Meruvian
On Oct 5, 2012 7:11 PM, "Jane Wayne" <ja...@gmail.com> wrote:

> not really/entirely what i'm looking for. the struts2-json-plugin
> supports json. but what about xml? i need the flexibility to alter
> between the two for the client/consumer of the rest services.
>
> On Thu, Oct 4, 2012 at 7:41 PM, Ken McWilliams <ke...@gmail.com>
> wrote:
> > I'm not familiar with this application but simply look at the
> > documentation for the struts2-json-plugin, you can specify a json
> > result and you can specify include and exclude parameters (so you just
> > return the part(s) of your Action you want). In this way you could
> > define a new map, put a key of "results" with a value of "New order
> > created successfully" and return it quite easily. If the struts2
> > document is insufficient there are plenty of examples also on
> > StackOverflow, so take a look there too (Including many annotation
> > based examples).
> >
> > On Thu, Oct 4, 2012 at 4:21 PM, Jane Wayne <ja...@gmail.com>
> wrote:
> >> i've downloaded the demo apps for struts 2 v2.3.5 SNAPSHOT for today.
> >> i am trying to understand and study the rest struts2-rest-showcase
> >> webapp.
> >>
> >> in the rest showcase, the OrdersController class has the following
> method.
> >>
> >> public String editNew() {
> >>  model = new Order();
> >>  return "editNew";
> >> }
> >>
> >> the user is taken to orders-editNew.jsp. on this page, the form posts
> >> to: action="%{#request.contextPath}/orders". the action to handle this
> >> form is as follows.
> >>
> >> public HttpHeaders create() {
> >>  ordersService.save(model);
> >>  addActionMessage("New order created successfully");
> >>  return new DefaultHttpHeaders("success").setLocationId(model.getId());
> >> }
> >>
> >> at this point, the user is taken to orders-index.jsp. however, i do
> >> not want to take the user to this page. i instead want to write a
> >> JSON/XML message back saying something (just like the action message)
> >> to indicate success/failure. how do i do this?
> >>
> >> i imagine my client application posting data to: /orders/new
> >> and then receiving some JSON message:
> >> { "results" : "New order created successfully" }
> >>
> >> any help is appreciated.
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: how to write json/xml output using struts 2 and rest + convention plugin

Posted by Jane Wayne <ja...@gmail.com>.
not really/entirely what i'm looking for. the struts2-json-plugin
supports json. but what about xml? i need the flexibility to alter
between the two for the client/consumer of the rest services.

On Thu, Oct 4, 2012 at 7:41 PM, Ken McWilliams <ke...@gmail.com> wrote:
> I'm not familiar with this application but simply look at the
> documentation for the struts2-json-plugin, you can specify a json
> result and you can specify include and exclude parameters (so you just
> return the part(s) of your Action you want). In this way you could
> define a new map, put a key of "results" with a value of "New order
> created successfully" and return it quite easily. If the struts2
> document is insufficient there are plenty of examples also on
> StackOverflow, so take a look there too (Including many annotation
> based examples).
>
> On Thu, Oct 4, 2012 at 4:21 PM, Jane Wayne <ja...@gmail.com> wrote:
>> i've downloaded the demo apps for struts 2 v2.3.5 SNAPSHOT for today.
>> i am trying to understand and study the rest struts2-rest-showcase
>> webapp.
>>
>> in the rest showcase, the OrdersController class has the following method.
>>
>> public String editNew() {
>>  model = new Order();
>>  return "editNew";
>> }
>>
>> the user is taken to orders-editNew.jsp. on this page, the form posts
>> to: action="%{#request.contextPath}/orders". the action to handle this
>> form is as follows.
>>
>> public HttpHeaders create() {
>>  ordersService.save(model);
>>  addActionMessage("New order created successfully");
>>  return new DefaultHttpHeaders("success").setLocationId(model.getId());
>> }
>>
>> at this point, the user is taken to orders-index.jsp. however, i do
>> not want to take the user to this page. i instead want to write a
>> JSON/XML message back saying something (just like the action message)
>> to indicate success/failure. how do i do this?
>>
>> i imagine my client application posting data to: /orders/new
>> and then receiving some JSON message:
>> { "results" : "New order created successfully" }
>>
>> any help is appreciated.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: how to write json/xml output using struts 2 and rest + convention plugin

Posted by Ken McWilliams <ke...@gmail.com>.
I'm not familiar with this application but simply look at the
documentation for the struts2-json-plugin, you can specify a json
result and you can specify include and exclude parameters (so you just
return the part(s) of your Action you want). In this way you could
define a new map, put a key of "results" with a value of "New order
created successfully" and return it quite easily. If the struts2
document is insufficient there are plenty of examples also on
StackOverflow, so take a look there too (Including many annotation
based examples).

On Thu, Oct 4, 2012 at 4:21 PM, Jane Wayne <ja...@gmail.com> wrote:
> i've downloaded the demo apps for struts 2 v2.3.5 SNAPSHOT for today.
> i am trying to understand and study the rest struts2-rest-showcase
> webapp.
>
> in the rest showcase, the OrdersController class has the following method.
>
> public String editNew() {
>  model = new Order();
>  return "editNew";
> }
>
> the user is taken to orders-editNew.jsp. on this page, the form posts
> to: action="%{#request.contextPath}/orders". the action to handle this
> form is as follows.
>
> public HttpHeaders create() {
>  ordersService.save(model);
>  addActionMessage("New order created successfully");
>  return new DefaultHttpHeaders("success").setLocationId(model.getId());
> }
>
> at this point, the user is taken to orders-index.jsp. however, i do
> not want to take the user to this page. i instead want to write a
> JSON/XML message back saying something (just like the action message)
> to indicate success/failure. how do i do this?
>
> i imagine my client application posting data to: /orders/new
> and then receiving some JSON message:
> { "results" : "New order created successfully" }
>
> any help is appreciated.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org