1

I have simplfied my code to make it easiear to understand:

I have an action class

public class MyAction extends ActionSupport {
  private BigClass item;

  public String myMethod(){
    //call some services
    this.item = processedStuff;
    return SUCCESS;
  }

}

and BigClass has an Array in it:

public class BigClass{
  private String data1;
  private String data2;
  private List<MyBean> dataArray=new ArrayList()<MyBean>;
  //setters and getters ...
}

and the strut.xml mapping

 <result name="success" type="json">
      <param name="includeProperties">
         item\.data1,
         item\.data2,
         item\.dataArray\[\d+\]\.id,
         item\.dataArray\[\d+\]\.name
      </param>

</result>

as json result, I'm only getting information data1, and data2, the array is not returning.. however if I change

item\.dataArray\[\d+\]\.id, 
item\.dataArray\[\d+\]\.name

to

 item\.dataArray.*,

I get all the information I need. is it the expression item\.dataArray\[\d+\]\.id incorrect?

Yichz
  • 9,250
  • 10
  • 54
  • 92

2 Answers2

1

In the struts.xml adding the extra two lines item\.dataArray, item\.dataArray\[\d+\], fixes the problem. I have also shown it below.

<result name="success" type="json">
   <param name="includeProperties">
     item\.data1,
     item\.data2,

     item\.dataArray,
     item\.dataArray\[\d+\],

     item\.dataArray\[\d+\]\.id,
     item\.dataArray\[\d+\]\.name
  </param>
</result>
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
Chaitanya
  • 11
  • 1
0

Please see this answer, and this rejected Suggestion :(
And make sure your OGNL expression is correct, both grammatically and logically.
"item\.dataArray\[\d+\]\.id" is grammatically correct, which will get values such as item.dataArray[0].id, item.dataArray[1].id, item.dataArray[2].id and so on.

Community
  • 1
  • 1
Hausen Zheng
  • 204
  • 1
  • 7
  • 1
    Hi, this is long time ago. I couldn't make it work as just is. what I did is to use item\.dataArray.* and then exclude properties I don't need :/ – Yichz Jun 11 '12 at 15:52
  • @Kossel "excludeProperties" overrides "includeProperties", so your solution works. I am just curious about the MyBean and json result. Maybe you could show us the json result by using your workable solution. – Hausen Zheng Jun 12 '12 at 01:32