Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Add the following validate method to Register.java (the Action class).

Code Block
JavajavaJava
java
titlevalidate method
	public void validate(){
		
		if ( personBean.getFirstName().length() == 0 ){	

			addFieldError( "personBean.firstName", "First name is required." );
			
		}
		
				
		if ( personBean.getEmail().length() == 0 ){	

			addFieldError( "personBean.email", "Email is required." );
			
		}
		
		if ( personBean.getAge() < 18 ){	

			addFieldError( "personBean.age", "Age is required and must be 18 or older" );
			
		}
		
		
	}

...

To handle the return value of "input" we need to add the following result to our action node in struts.xml.

Code Block
XMLxmlXML
xml
<result name="input">/register.jsp</result>

...

So the following addFieldError method call:

Code Block
JavajavaJava
java
addFieldError( "personBean.firstName", "First name is required.")

...