struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Beal <jb...@webmedx.com>
Subject Re: Which setter do I need in the ActionForm for this example?
Date Mon, 27 Dec 2004 14:06:59 GMT
I think this goes back to what Richard said a few posts back.  The 
collection used to populate a select list is distinct from what the 
browser sends back.  Let's say you have a map that looks something like 
this:
  { [001,"Value 1"],[002,"Value 2"],[003,"Value 3"],[004,"Value 4"] }

(I just made that syntax up on the spot.  The Map has four String values 
with keys 001 to 004.)  The <html:select/> with an 
<html:optionsCollection/> will generate the following HTML:

<select name='dropDown' multiple='true'>
  <option value='001'>Value 1</option>
  <option value='002'>Value 2</option>
  <option value='003'>Value 3</option>
  <option value='004'>Value 4</option>
</select>

If the user selects 'Value 2' and 'Value 4', the browser will send back 
the following to the server:

http://www.yourcompany.com/yourapp/youraction.do?dropDown=002&dropDown=004

Note that 'Value 2' and 'Value 4' do not get sent to the server.  Only 
the keys get sent.

On the server side, the two values for the dropDown parameter are 
exposed as a String array ({"002","004"}).  Read the documentation for 
request.getParameter and request.getParameterValues for more information 
on this.   What you want in your ActionForm is (I think):

public void setDropDown(String[] selectedKeys)
public String[] getDropDown()

Forget that a Map was used to populate the select list.  That's purely a 
convenience provided by the <html:select/> and <html:optionsCollection/> 
custom tags.

-- Jeff

Zsolt Koppany wrote:
> I think, I have found the reason of the problem but still don't understand
> it. If I use "getDropDownSelection()" instead of "getDropDownSelections()"
> to get the Map back the setter method "setDropDownSelection(String key,
> String[] v)" is not called.
> 
> Do I misunderstand something?
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message