0

My form has a parameter consisting of a grid/table (presented via s:iterator) of data together with other fields represented in my action class as:

public class MyAction extends ActionSupport {
  private MyParameter param;

  public String execute() { ..... }
  // getter and setters 
}

Here is MyParameter class:

public class MyParameter {
  private List<GridData> gridDataList;
  private String subParam1;
  private String subParam2;
  // getters and setters here
}

Here is GridData:

public class GridData {
  private String title;
  private String arg1;
  // etc... getters and setters...
}

I am able to successfully submit the values of grid data to perform some validation. I am able to add field errors to other parameters by this:

super.addFieldError("param.subParam1", "subParam1 error message");
super.addFieldError("param.subParam2", "subParam2 error message");

What I would like to do is to iterate through my list, and add error messages to each of the elements in the list. I tried doing the following but it does not seem to work:

for(int intRow=0; intRow < param.griDataList.size(); intRow++) {
  super.addFieldError("param.gridDataList[" + intRow + "].arg1", "error message");
}

I then rendered the field errors in JSP using iterator. I know that the above is possible because when I check the generated HTML after processing, the field show the 'cssErrorClass' that I have set in JSP. That is:

<s:textfield
name="param.gridDataList[%{#outerStat}].data"
cssClass="grid_text_field"
cssErrorClass="error_field" maxlength="7"/>

Where outerStat is the status (counter) set in the iterator. This generates:

<input
type="text"
name="param.gridDataList[0].data"
class="grid_text_field error_field"
maxlength="7"/>

But no field error message is generated in the tag:

<s:fielderror fieldName="param.gridDataList[%{#outerStat}].data"/>

Can anyone kindly point out what I have done wrong here?

nmenego
  • 846
  • 3
  • 17
  • 36

1 Answers1

0

First of all correct usage of fielderror tag is <s:fielderror fieldName="some_field_name"/>. And some_field_name must be String not expression http://struts.apache.org/2.x/docs/fielderror.html.

One of the way to do this is to access fieldError map in property tag
<s:property value="fieldErrors.param[%{index}].arg"/>

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
  • I apologize for the mistake. I corrected the sample code. In my actual code, I used `fieldName` instead of `name`. I mistakenly wrote it that way. The error is successfully registered but is not printed out. Is `s:property` tag the only way? – nmenego Sep 30 '12 at 06:03
  • Why don't you like `s:property` tag? If you want to style field error then you can write table cells and css class yourself. – Aleksandr M Sep 30 '12 at 13:50