Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to validate multiple text boxes of same name

 
P Currid
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9520
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
P Currid
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9520
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then probably you should try this

 
P Currid
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic