i'm having a problem with struts' population of a form with an indexed property. specifically, BeanUtils.setProperty is barfing (and something in the stack is annoyingly swallowing the exception) when trying to set a nested property on the indexed property.

(see the form, jsp, generated html and log output snippets below)

this is my first real attempt at using indexed properties, so i may have missed something obvious. i read the user guide section and the faq page before starting, but that doc doesn't seem to cover precisely what i'm doing.

i wonder if the problem is that the IpValue[] form property has size zero when the bean is populated? i assumed that BeanUtils would instantiate the array and set it as needed, retrieving and growing it each time setProperty is called for the indexed field. to see if i was wrong, i tried using the setter signature that's found in the faq entry (see indexed setter snippet below), but i got the same result as before.

what am i missing? something simple, i'm sure.

thanks for your help!

== form class (relevant bits included)

public class PlatformForm extends ActionForm {

private IpValue[] ip;

public IpValue[] getIp() {
return this.ip;
}

public void setIp(IpValue[] ip) {
this.ip = ip;
}

}

== jsp (static text removed for bretivy)

<logic:iterate collection="${ips}" id="ip" indexId="index">
<tr>
<td><html:text size="30" name="ip" property="address" indexed="true"/></td>
<td><html:text size="30" name="ip" property="netmask" indexed="true"/></td>
</tr>
</logic:iterate>

== generated html

<tr>
<td><input type="text" name="ip[0].address" size="30" value="10.0.1.6"></td>
<td><input type="text" name="ip[0].netmask" size="30" value="255.255.255.0"></td>
</tr>

== log output

16:17:46,936 DEBUG [BeanUtils] setProperty(startTime=now startMonth=null startDay=null startYear=null startHour=00 startMin=00 startAmPm=am startTimeZone=PST recurInterval=null recurrenceFrequencyDaily=everyDay numDays=1 numWeeks=1 recurrenceDay=[Ljava.lang.Integer;@74cc4e recurrenceFrequencyMonthly=onDay numMonths=1 recurrenceWeek=null eachDay=null endTime=none endMonth=null endDay=null rid=null type=null name=null location=null description=null cpuCount=null cpuSpeed=null dhcpServer=null dnsServer=null fqdn=null gateway= ram=null ip=[], ip[0].address, [10.0.1.6])

== indexed setter

public void setIp(int index, IpValue ip) {
if (this.ip == null) {
this.ip = new IpValue[0];
}

int numIps = this.ip.length;
if (index >= numIps) {
IpValue[] newIps = new IpValue[numIps+1];
System.arraycopy(this.ip, 0, newIps, 0, numIps);
this.ip = newIps;
}

this.ip[index] = ip;
}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to