1

I have used Struts2 json like this

<package name="showcase" extends="json-default" >  

    <action name="DashBoardActivityJson" class="com.myDrDirect.doctor.action.patientOrderDetails" method="getRecentOrderDetails" >
       <result name="success" type="json" />
    </action>               
 </package>

But here my problem is little bit crazy. When i access a function inside a class it call every function in the page even though i have mention here method name. That is when i set type="json" the action call both getRecentOrderDetails and getUserDetailses from the class com.myDrDirect.doctor.action.patientOrderDetails but here i only call getRecentOrderDetails. Do anybody feels this problem before, please help.

Umesh Awasthi
  • 23,407
  • 37
  • 132
  • 204
user359187
  • 2,269
  • 6
  • 29
  • 44

3 Answers3

3

I believe JSON plugin trying to call each method starting with name "get" for serializing the output. One way is to rename the method to some other generic way to handle this.else you can include and excludes the parameters.Refer to the plugin documents for details

json-plugin

Umesh Awasthi
  • 23,407
  • 37
  • 132
  • 204
  • Yes you are right. But i have done major portion of my project and have lot of functions starting with get. Any idea about how could i manage it? – user359187 Feb 02 '12 at 09:20
  • Hi i have confused with the exludeProperties,includeProperties,enableSMD and excludeNullProperties. I have added a question please check http://stackoverflow.com/questions/9115264/how-to-the-excludeproperties-working-in-struts2 – user359187 Feb 02 '12 at 15:48
1

The struts2-json-plugin serializes your action, as such what you describe is the expected behaviour. To get around this the plugin provides include and exclude parameters which modify the serialization such that it prunes the object into a form you want.

In this question there is a good example of this: Struts2 + Json Serialization of items and here is another Problem with Json plugin in Struts 2

Please consult the plugin documentation on the struts2 site: http://struts.apache.org/2.2.3/docs/json-plugin.html this will explain how to use xml or annotations.

Community
  • 1
  • 1
Quaternion
  • 10,380
  • 6
  • 51
  • 102
  • Thanks Quaternion but it is not solved my problem. All the above link explains how to solve the issue in using annotations but unfortunately i am not using struts annotaion tag in my project. Also i have checked the link struts.apache.org/2.2.3/docs/json-plugin.html and also i have tried this but it not solved my problem. It is still call all functions in my project when i refer type="action" in my action. Can you suggest me another solution for it. It will be really helpful for me – user359187 Feb 05 '12 at 18:46
  • 1
    Why not give annotations a shot? Just try a JSON action with them, and if it does not do what's expected post it here. With struts2 xml you need to look at the xml file and the action to see what's going on with annotations, you just need the action. There is only a gain, no loss at all especially when using struts2-conventions-plugin. – Quaternion Feb 06 '12 at 19:40
  • But i am already using my half portion of the project without using struts annotations. Can i integrate that from this stage? – user359187 Feb 07 '12 at 06:40
  • Absolutely. Adding annotations should not affect your project. You should look into the conventions plugin too... again it all works in a sensible way, you can save a lot of writing xml... but it does not stop you from using xml to do what you want. Some things are better in the xml, global settings and interceptor stack definitions make the most sense there but action specific things are most easily understood in the action. Again just try with the json annotations to start. If you give the conventions plug in a shot I bet you'll wish you had done so earlier (I did). – Quaternion Feb 07 '12 at 18:46
0

I got it correct when i write the action in a seperate file. Than you guys for helping to solve the issue.

user359187
  • 2,269
  • 6
  • 29
  • 44