You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dave Hodson <da...@messagecast.net> on 2002/07/07 07:04:34 UTC
Re: Problem populating form bean with multiple parameters of same name
I found the post below in the mail archives, but could not find any followups.
Anyone have an idea how to get around the issue of "how Struts can read multiple text input
fields, all with the same name (akin to ServletRequest.getParameterValues(String s) ), and
properly populate those same fields when the JSP is displayed again"?
Dave
_____
* From: Steven Valin
* Subject: Re: Problem populating form bean with multiple parameters of same name
* Date: Sun, 21 Oct 2001 06:03:15 -0700
_____
Renaud,
I appreciate your response, but unfortunately when the JSP is regenerated and
displayed, Struts places the toString() value of the String array into the
<html:text property="propertyName" size="20"/> tags, such as:
[Ljava.lang.String;@262bf4
I have also tried a twist on this strategy, with:
private String propertyName[];
private int propertyNameIndex;
public void setPropertyName(String[] propertyName) {
this.propertyName = propertyName;
propertyNameIndex = 0;
}
public String getPropertyName() { // send default value if index out of
range
return ((propertyNameIndex < propertyName.length) ?
propertyName[propertyNameIndex++] : "");
}
I was hoping that this strategy would allow the JSP to populate each <html:text
.../> field with successive calls to getPropertyName() but this then results in:
javax.servlet.jsp.JspException: Exception thrown by getter for property fileName
of bean org.apache.struts.taglib.html.BEAN
at org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:513)
If anybody has any other ideas on how Struts can read multiple text input
fields, all with the same name (akin to ServletRequest.getParameterValues(String
s) ), and properly populate those same fields when the JSP is displayed again, I
would greatly appreciate your thoughts!
TIA, Steve
Renaud Waldura wrote:
> Have you tried declaring your property as an array of strings?
>
> private String propertyName[];
> public String[] getPropertyName() { ... }
> public void setPropertyName(String[] propertyName) { ... }
>
> It may just work. In general I've found Struts to be amazingly flexible with
> properties and their types. Kudos to the Struts developers!
>
> --Renaud
>
--
Steven Valin
steven.valin@javelinsoftware.com
---
Dave Hodson
MessageCast, inc.
Email: dave@messagecast.net
www.messagecast.net
RE: Problem populating form bean with multiple parameters of same name
Posted by James Mitchell <jm...@telocity.com>.
Yes, indexed properties.
here's a link to get you started...
http://husted.com/struts/resources/indexed-tags.htm
James Mitchell
Software Engineer\Struts Evangelist
Struts-Atlanta, the "Open Minded Developer Network"
http://www.open-tools.org/struts-atlanta
> -----Original Message-----
> From: Dave Hodson [mailto:dave@messagecast.net]
> Sent: Sunday, July 07, 2002 1:05 AM
> To: struts-user@jakarta.apache.org
> Subject: Re: Problem populating form bean with multiple parameters of
> same name
>
>
> I found the post below in the mail archives, but could not find
> any followups.
> Anyone have an idea how to get around the issue of "how Struts
> can read multiple text input
> fields, all with the same name (akin to
> ServletRequest.getParameterValues(String s) ), and
> properly populate those same fields when the JSP is displayed again"?
> Dave
>
>
> _____
>
>
>
> * From: Steven Valin
>
> * Subject: Re: Problem populating form bean with multiple
> parameters of same name
>
> * Date: Sun, 21 Oct 2001 06:03:15 -0700
>
> _____
>
> Renaud,
>
>
>
> I appreciate your response, but unfortunately when the JSP is
> regenerated and
>
> displayed, Struts places the toString() value of the String array into the
>
> <html:text property="propertyName" size="20"/> tags, such as:
>
>
>
> [Ljava.lang.String;@262bf4
>
>
>
> I have also tried a twist on this strategy, with:
>
>
>
> private String propertyName[];
>
> private int propertyNameIndex;
>
>
>
> public void setPropertyName(String[] propertyName) {
>
> this.propertyName = propertyName;
>
> propertyNameIndex = 0;
>
> }
>
>
>
> public String getPropertyName() { // send default value if
> index out of
>
> range
>
> return ((propertyNameIndex < propertyName.length) ?
>
> propertyName[propertyNameIndex++] : "");
>
> }
>
>
>
> I was hoping that this strategy would allow the JSP to populate
> each <html:text
>
> .../> field with successive calls to getPropertyName() but this
> then results in:
>
>
>
> javax.servlet.jsp.JspException: Exception thrown by getter for
> property fileName
>
> of bean org.apache.struts.taglib.html.BEAN
>
> at org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:513)
>
>
>
>
>
> If anybody has any other ideas on how Struts can read multiple text input
>
> fields, all with the same name (akin to
> ServletRequest.getParameterValues(String
>
> s) ), and properly populate those same fields when the JSP is
> displayed again, I
>
> would greatly appreciate your thoughts!
>
>
>
> TIA, Steve
>
>
>
>
>
> Renaud Waldura wrote:
>
>
>
> > Have you tried declaring your property as an array of strings?
>
> >
>
> > private String propertyName[];
>
> > public String[] getPropertyName() { ... }
>
> > public void setPropertyName(String[] propertyName) { ... }
>
> >
>
> > It may just work. In general I've found Struts to be amazingly
> flexible with
>
> > properties and their types. Kudos to the Struts developers!
>
> >
>
> > --Renaud
>
> >
>
>
>
> --
>
> Steven Valin
>
> steven.valin@javelinsoftware.com
> ---
> Dave Hodson
> MessageCast, inc.
> Email: dave@messagecast.net
> www.messagecast.net
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>