You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Alberto A. Flores" <aa...@gmail.com> on 2007/12/14 21:15:15 UTC

StrutsTypeConverter API

Does anyone knows why the API for the StrutsTypeConverter abstract class 
takes an array of Strings instead of a single one (the convertFromString 
method)? The sample app seems to be always checking for the first 
element. Is OGNL supposed to add more?  Any feedback will be appreciated...

Thanks!

-- 

Alberto A. Flores
http://www.linkedin.com/in/aflores



Re: StrutsTypeConverter API

Posted by Gary Affonso <gl...@greywether.com>.
Alberto A. Flores wrote:
> Does anyone knows why the API for the StrutsTypeConverter abstract class 
> takes an array of Strings instead of a single one (the convertFromString 
> method)? The sample app seems to be always checking for the first 
> element. Is OGNL supposed to add more?  Any feedback will be appreciated...

Because the data passed in to the Servlet (via get or post) is an array 
of strings.  The type converters are simply using the passed-in data.

This doesn't make immediate sense since most forms have uniquely named 
form fields.

But that's not a requirement.  It's valid to do this:

  <input type="text" name="textfield" />
  <input type="text" name="textfield" />
  <input type="text" name="textfield" />


When the user enters data into those three fields and "posts" the 
servlet has to handle an *array* of submitted values (since three values 
will be posted, all associated with that single fieldname).

This "multiple values per name" situation is uncommon with text fields 
(but possible, as noted above) but fairly common with radio buttons and 
select lists with the "multiple" attribute enabled.

In short: because the servlet must always handle the *possibility* that 
more than one value exists for any given key, its datatype for 
representing those values is an array.  And the converters are 
converting from that servlet datatype into whatever the target datatype is.

- Gary

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