5

Sorry, I really don't know how to summarize the title of this question. So, the title may not be clear.

I have an action class which performs some business logic.

in the Action Class:

class ActionClass extends ActionSupport{
      private Merchandise merchandise;// I want to transfer it to the client
      //setter and getter

}

in the Merchandise class:

class Merchandise{
    private String name; // I want to transfer it
    private String price; //I don't want to transfer it
    private String description;//I don't want to transfer it
    //setter and getter
}

Now, I need to transfer the merchandise property in ActionClass to the client.

However, in the merchandise property, I want to transfer only the name property while inhibiting the other two properties.

Then how to inhibit the transfer of the other two properties(price and description) in class Merchandise?

xiaohan2012
  • 9,870
  • 23
  • 67
  • 101
  • can you explain more on "I want to filter those properties and transfer only a portion of them" with some example if possible – Anupam Aug 03 '11 at 10:12

3 Answers3

5

Try something like:

<!-- Result fragment -->
<result type="json">
  <param name="root">merchandise</param>
  <param name="excludeProperties">price,description</param>
</result>

See full documentation, other options and examples at http://struts.apache.org/2.2.3/docs/json-plugin.html

nmc
  • 8,724
  • 5
  • 36
  • 68
0

The easiest way is to create a Data Transfer Object in your action class that contains only the fields you want to send to the client and make that your root object

user497087
  • 1,561
  • 3
  • 24
  • 41
0

@nmc answer is correct another way you can try like:

<result type="json">
  <param name="root">merchandise</param>
  <param name="includeProperties">name</param>
</result>

Or

    <result type="json">
     <param name="includeProperties">
       merchandise.name
     </param>
     <param name="root">
       #action
     </param>
    </result>
xrcwrn
  • 5,339
  • 17
  • 68
  • 129