tags:

views:

32

answers:

1

Hello,

I have view.jsp and edit.jsp pages. Both call load() method of an action, which returns SUCCESS. Is there a way to forward to the page request came from in struts.xml, instead of this?

<action name="call_1" method="load" class="package.action.List">
  <result name="success" type="json">/WEB-INF/view.jsp</result>
</action>
<action name="call_2" method="load" class="package.action.List">
  <result name="success" type="json">/WEB-INF/edit.jsp</result>
</action>

Also, my action builds hashmap as {"3":"adam","1":"brian","2":"brit","4":"den"}, which is used to populate a drop down menu. It is sorted based on values, but for some reason json still dispaly it in the following order. brian->brit->adam->den. Why is still being sorted based on keys when keys are strings.

+1  A: 

Yes, you can use wildcard mappings to condense your two <action> definitions into one.

<action name="list-*" method="load" class="package.action.List">
    <result name="success" type="json">/WEB-INF/{1}.jsp</result>
</action>

The above will take the part after the hyphen in the action request URL and use it set the result location. You could then call it with either of these two URLs:

http://yourapp.com/list-view.action
http://yourapp.com/list-edit.action

As for sorting your JSON object, you can read this answer for more details on how to create a comparator and get it in the order you want.

Pat
thanks a lot savior!
Nishant
I now get how to sort JSON if it is object, but mine is not so. Here is what I get from an action:{"studentMap":{3":"adam","1":"brian","2":"brit","4":"den"}}So you see, I dont have fields to sort by.
Nishant