Derek Conniffe wrote:
>
> Hi,
>
> I was wondering if you ever got a result to your problem (below). I did not
> see a reply in the JSP-INTEREST list.
>
> I now have a requirement to be able to pull in values from multiple From
> elements with the same name into a Bean set method. EG:
>
> <h1>
> Enter the First Number:
> <input type="text" name="ANumber">
> </h1>
> <h1>
> Enter the Second Number:
> <input type="text" name="ANumber">
> </h1>
>
> This is a simple task in perl (with CGI.pm) - which returns a Vector of
> values.
>
> Is there any way to do this with a Bean's set method?
Sure, the <jsp:setProperty> action handles multi-value parameters.
Your JavaBean class needs a set method with a String[] argument, e.g.
public void setNumbers(String[] numbers)
Then you can use <jsp:setProperty> in a JSP page to set the property to
the array of values:
<jsp:useBean name="foo" class="myBean">
<jsp:setProperty name="foo" property="numbers" param="ANumber" />
</jsp:useBean>
To make it even easier you may want to use a name for your form field
that directly match the property name, i.e. replace "ANumber" with "numbers"
in this example (property names should start with a lower case letter).
You can then let the JSP engine figure out which property to set based
on the HTTP parameter name, e.g.
<jsp:useBean name="foo" class="myBean">
<jsp:setProperty name="foo" property="*" />
</jsp:useBean>
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html