jump to navigation

DynaActionForm Properties not set – BUG with indexed form properties March 7, 2008

Posted by Tomas in IBM Webspehere.
Tags:
1 comment so far

One of the most annoying “features” of the Websphere Portal that it uses butchered (aka modified) Struts 1.1 Framework. During this “modification” some things fell through the cracks and some interesting bugs got introduced. I spend 2 days blidly debugging this piece of shit portal to find a workaround.

Here is the problem: You have a DispactchAction and a DynaActionForm you add indexed properties on your jsp page and some of those indexed properties are not being set. If you debug it, you see the values in the request, but they never make it to the form. And some of the other form properties, not only indexed are not being set out of a sudden. If you remove the indexed properties from the form and jsp everything starts working.

The bug lies somewhere in the modified struts framework. Modified code does not recognize a setter method with signature setSomething( String value) as a valid setter method. This bug only surfaces if indexed properties exist in the form and jsp. To get around this bug you must change the signature to setSomethig( Object value ) and you get the values.

Here is the example:

Form:
<form-bean name=”roleForm” type=”org.apache.struts.action.DynaActionForm”>
<form-property name=”role”
<form-property name=”attribute” type=”com.something.model.Attribute[]” size=”100″ />
</form-bean>

Jsp:
<logic:iterate id=”attribute” name=”roleForm” property=”role.attributes” >
<tr>
<td>
<html:hidden indexed=”true” name=”attribute” property=”id” />
<html:hidden indexed=”true” name=”attribute” property=”version” />
<html:text indexed=”true” property=”key” name=”attribute” size=”20″ maxlength=”250″ />
</td>
<td><html:text indexed=”true” property=”value” name=”attribute” size=”20″ maxlength=”250″ /></td>
<td><input type=”submit” value=”Delete” /></td>
</tr>
</logic:iterate>

Which produces:
<tr>
<td>
<input type=”hidden” name=”attribute[0].id” value=”1″>
<input type=”hidden” name=”attribute[0].version” value=”1″>
<input type=”text” name=”attribute[0].key” maxlength=”250″ size=”20″ value=”TEST”>
</td>
<td><input type=”text” name=”attribute[0].value” maxlength=”250″ size=”20″ value=”TEST2″></td>
<td><input type=”submit” value=”Delete” /></td>
</tr>

So you must have:
public void setKey(String key) {
this._key = key;
}
public void setKey(Object key) {
this._key = key.toString();
}

For this to work.