1

I have a Struts2 application where I using Tiles. How can I get multiple result types in action-mappings? because I need to set de output as JSON data, and Tiles simultaneous. I have tried:

<action
    name="home"
    class="com.deveto.struts.actions.HomeAction" >
    <result name="success" type="tiles,json">tiles.home</result>
</action>

But this isn't working

Denees
  • 9,100
  • 13
  • 47
  • 76
  • 1
    You cannot have multiple types for a response; you can only commit a single response to an HTTP request. Perhaps you can explain in more detail what you are trying to do. – Steven Benitez Jun 23 '11 at 16:48
  • As steven said you can not have both. It doesn't make sense. `tiles` result type gives you the HTML whereas `json` type gives you the ... well ... JSON ;) – doctrey Jun 23 '11 at 20:32

3 Answers3

5

To my knowledge there is no way to return multiple things simultaneously. The browser will only be expecting one thing, either the JSON or the HTML once all the tiles stuff is done.

I can think of two ways to do this: double request (one for each result type) or use one to generate the other (get the JSON and use JavaScript to construct the HTML on the client).

What are you trying to accomplish that you need both results?

MBCook
  • 14,424
  • 7
  • 37
  • 41
2

create a new result type for Tiles+JSON & use it... you can't define 2 result types in a result tag.

Anantha Sharma
  • 9,920
  • 4
  • 33
  • 35
0

How about if u have 2 diff results?!

<result name="successJSON" type="json"/>

<result name="successTiles" type="tiles">tiles.home</result>

then in your server code u just route to the right one?!

Quaternion
  • 10,380
  • 6
  • 51
  • 102
Arthur Neves
  • 11,840
  • 8
  • 60
  • 73
  • Not a solution, I need to get it simultaneous, if I set type to JSON only, then I can get tiles to work – Denees Jun 23 '11 at 14:56
  • the json result type is used almost exclusively for ajax. So one would assume that is what he's after. However tiles renders a page just like a JSP, so one would then need to assume it isn't. – Quaternion Jun 23 '11 at 18:23