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 !!
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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With