4

In my jsp, I have some fields like this :

<html:text property="field[0]" value="${fieldValue}" indexed="true">
<html:text property="field[1]" value="${fieldValue}" indexed="true">
<html:text property="field[2]" value="${fieldValue}" indexed="true">
<html:text property="field[3]" value="${fieldValue}" indexed="true">

And in my form I have a java.util.list that I need to populate from the fields on top :

private List<Double> field = new ArrayList<Double>();

public final List<Double> getField() {
    return field;
}
public final void setField(final List<Double> valeur) {
    this.field = valeur;
}

The problem is that the list is not populated. Any ideas ??? Thanks !!

Marouane Gazanayi
  • 5,063
  • 6
  • 39
  • 58

2 Answers2

1

According to my knowledge,
1. If it is struts 1, the dollar "$" field does not work to take the values. 2. You should not specify the index in the property name, but it will be automatically used by the tag translator and hence your code will something look like

 <html:text property="field" indexed="true"> 
 <html:text property="field" indexed="true">
 <html:text property="field" indexed="true">
 <html:text property="field" indexed="true">  

I hope this helps you to solve your problem.

Naved
  • 4,020
  • 4
  • 31
  • 45
  • Thanx for your reply. I already did this, and the problem is not from the $. Why I want to use a List ? It's for validation, for that if the third field is on error, I want to see just this field on error and not all the fields... – Marouane Gazanayi Dec 05 '11 at 13:36
  • In my example, You have to add List. But you can not have to provide index in the "property". – Naved Dec 06 '11 at 06:06
1

Simply do this

<html:text property="field[0]" value="${fieldValue}" indexed="true">
<html:text property="field[1]" value="${fieldValue}" indexed="true">
<html:text property="field[2]" value="${fieldValue}" indexed="true">
<html:text property="field[3]" value="${fieldValue}" indexed="true">

And in the form :

private String[] field = new String[0];

public final String getField(int index) {
    return field[index];
}
public final void setField(int index, String value) {
    //Copy last values of the array into a temporary array, then add the new value
    String[tmp] = new String[index + 1];
    for(int i=0; i<field.length; i++){
        tmp[i] = field[i];
    }
    tmp[index] = value;
    this.field = tmp;
}
Marouane Gazanayi
  • 5,063
  • 6
  • 39
  • 58