This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes how to validate multiple text boxes of same name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to validate multiple text boxes of same name" Watch "how to validate multiple text boxes of same name" New topic
Author

how to validate multiple text boxes of same name

P Currid
Greenhorn

Joined: Apr 07, 2009
Posts: 6
Hi,
I'm having trouble with a struts project which requires multiple (up to 50) text boxes of the same name.
I'm sure there's a simple enough way to create this using a string array, but I'm not sure how!
I only have the need to use struts a few times a year so my knowledge is not all that great.
Any help at all would be so much appreciated!!

Below is my action form:

package strutspackage;
import org.apache.struts.validator.ValidatorForm;

public class AppForm extends ValidatorForm {

private static final long serialVersionUID = 1L;
private String[] firstName;

public static long getSerialVersionUID() {
return serialVersionUID;
}
public String[] getFirstName() {
return firstName;
}

public void setFirstName(String[] firstName) {
this.firstName = firstName;
}


}

Here is my validation.xml:
<field
property="firstName[]"
depends="mask"
page="1">
<arg key="genericInvalid.amount"/>
<var>
<var-name>mask</var-name>
<var-value>^[0-9]*$</var-value>
</var>
</field>

And my jsp is:
<html:form action="/aibbusiBBApp2.do" >
Name
<html:text property="firstName[]" maxlength="50"/><br /><br />

Name
<html:text property="firstName[]" maxlength="50"/><br /><br />
</html:form>


When I run this I get the following errors:
org.apache.jasper.JasperException: Invalid argument looking up property firstName[] of bean org.apache.struts.taglib.html.BEAN
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

javax.servlet.ServletException: Invalid argument looking up property firstName[] of bean org.apache.struts.taglib.html.BEAN
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.App1_jsp._jspService(App1_jsp.java:172)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Well I don't know much about validations, but why don't you try this





Also try to go through a few tutorials like this or this...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
P Currid
Greenhorn

Joined: Apr 07, 2009
Posts: 6
hi,
yeah I did try this, but I was receiving the following when I tried to submit the form:
Within the text field the following value was being populated:
[Ljava.lang.String;@18e80a6

Any ideas as to how to get around this?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Then probably you should try this

P Currid
Greenhorn

Joined: Apr 07, 2009
Posts: 6
the problem with specifing the index value of these is that there can be up to 50 firstnames added.
Because this is part of an application form, I have to pass these values as hidden variables through to the last page.
If I use the firstName[0] / firstName[1] option, I'll have to specify each as a separate hidden variable.

So I need to keep each text field with the same name, ie firstName[], so that I don't have to potentially pass 50 hidden variables,
and instead, can just pass through the array.
Does this make sense?!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to validate multiple text boxes of same name
 
Similar Threads
Getting exception on deployment to Tomcat using JSF
javax.servlet.ServletException: Name java: is not bound in this Context
Exception while running Struts
Struts validation problem with string array for text fields
Connecting JSP to MySQL