Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0
Info

This tutorial assumes you've completed the Processing Forms tutorial and have a working form_processing project. The example code for this tutorial, form_validation, is available for checkout from the Struts 2 sandbox subversion repository: https://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2examplesImage Removed.

Introduction

...

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

Code Block
javajava
titlevalidate method
java
	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" );
			
		}
		
		
	}

...