Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

struts validation

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm try to validate a form using struts Form with Validator, I want to validate the no input & maxlength. I've setup the configs but when I test the form it only shows "Validation Error(s), UserName is required."
even if I've put a username.. why?

part code:

form jsp

<html:javascript formName="loginForm"/>
</head>

<html:form action="/login">

<td width="15%">Enter your name:</td>
<td width="85%">
<html:text property="name" size="25" maxlength="50"
onfocus="this.select()"/>
</td>
</tr>
-------------------------------------------------------------------------------------------------------------
LoginForm


public class LoginForm extends org.apache.struts.validator.ValidatorForm{

private String name = null;

private String result ;

public void setName(String name) {
this.name = name;
}

public String getName() {
return name;
}



public void setResult(String result) {
this.result = result;
}

public String getResult() {
return result;
}
---------------------------------------------------------------------------------------------------------------
validation.xml


<form name="loginForm">
<field
property="username"
depends="required,maxlength">

<arg position="0" key="loginForm.username"/>
<arg position="1" key="${var:maxlength}" name="maxlength"
resource="false"/>
<var>
<var-name>maxlength</var-name>
<var-value>10</var-value>
</var>
</field>

</form>



 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

<field property="username" depends="required,maxlength">



I dont have much experience in Struts, but shouldn't the propert be "name" instead of "username" because your LoginForm and the jsp have it as "name"

Try this:

<field property="name" depends="required,maxlength">

 
Wait for it ... wait .... wait .... NOW! Pafiffle! A perfect tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!