I have a form with a field that may have zero to multiple values for the named field, e.g.,:
<form ...>
<input type="hidden" name="browseId[]" value="3">
<input type="hidden" name="browseId[]" value="4">
<input type="hidden" name="browseId[]" value="8">
<input type="hidden" name="browseId[]" value="10">
<input type="text" name="browseId[]">
...
</form>
I do not seem to be able to get the variable browseId
as an array, which is standard operating procedure in HTML, other languages, and I'm stumped. I'm actually first processing the form output in a validation method, using a DynaActionForm:
public static ActionMessages validatePlacement(DynaActionForm form) {
String[] rootBrowseIds = (String []) form.get("browseId");
...
}
Here's the form bean and action definition in struts-config.xml:
<form-bean name="placementForm" type="org.apache.struts.validator.DynaValidatorForm">
<!-- I've tried a few variations -->
<!--<form-property name="browseId" type="java.lang.String"/>-->
<!--<form-property name="browseIds" type="java.lang.String[]"/>-->
<form-property name="browseId" type="java.lang.String[]"/>
...
</form-bean>
...
<action path="/admin/editPlacement"
type="com.rc.mexp.action.admin.placementinventory.EditPlacementAction"
name="placementForm">
<forward name="success" path="/WEB-INF/pages/admin/placement/placementEdit.jsp"/>
<forward name="error" path="/admin/managePlacementInventory.do"/>
</action>
It appears that only the last value, empty in this case, is being received by Struts. WTF?
Any ideas?
Is there a way to change my form-bean definition to include something like this? I'm not allowed to use the <
and >
characters inside the type:
<form-property name="browseId" type="java.util.Map<java.lang.String[]>"/>
Other stackoverflow Qs that I examined already:
retrieve multiple inputs of the same name from jsp to struts (does not seem relevant)
Multiple inputs with same name through POST in php
Struts 2 - pattern/strategy for multiple objects on the same page
You're accessing the form field incorrectly, you should be using getStrings("browseId")
since you're trying to get multiple strings.
Your code won't even compile for me, I'm not sure why you don't get a class cast exception.