struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jane Wayne <jane.wayne2...@gmail.com>
Subject Re: how to write json/xml output using struts 2 and rest + convention plugin
Date Fri, 05 Oct 2012 14:12:53 GMT
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 <frans@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" <jane.wayne2978@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 <jane.wayne2978@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


Mime
View raw message