File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts and Vlidation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts and Vlidation" Watch "Struts and Vlidation" New topic

Struts and Vlidation

Aash Patel

Joined: Sep 14, 2005
Posts: 24
I have designed a fully function struts application. I am at the point of implemeneting Validation for my application.

So for starters this is what I would like to do:

The entry point into my application is a logon page that prompts the user to enter a username, password, and database name (automatically populated in a drop down menu). The user then clicks on a Connect button that opens a database connection to the specified database. Everything works fine if the user enters valid data.

I now need to implement validation as below:
1. If the user doesn't enter anything for username or password.
2. If the user enters an invalid username or password.

I can do 1 using the validate method in my ActionForm. However I don't understand how the control flow for this works - as in how and what I need to change in my struts-config.xml and my JSP page and my properties file.

I don't know where to start from for 2.

I'd greatly appreciate any assistance on 1 or 2 or both,
Pranav Sharma
Ranch Hand

Joined: Oct 27, 2003
Posts: 258
go through the struts validation documentation here.
That should clear up most of your doubts
Aash Patel

Joined: Sep 14, 2005
Posts: 24
I went through the documentation for Struts Validation. Thank you mannu.

I am however having problems with my validation.xml and validation-rules.xml. Firstly, I'm not sure if these files are being deployed. Secondly, when I try to validate them (in JBuilder X), I get this error:

IOException: for both files.

validator-rules.xml is automatically generated by JBuilder when the validation option in struts is selected. I don't know why this doesn't work and this is how my validation.xml looks like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN" "">
<form name="logonActionForm">
<field property="dbName"
<arg0 key="validateform.username"/>
<field property="dbPassword"
<arg0 key="validateform.password"/>

What am I missing? Please assist. Thanks.
Aash Patel

Joined: Sep 14, 2005
Posts: 24
OK. I figured out why my validation.xml was not valid - My formset tag was not closed properly at the end. However I still cant get my validator-rules.xml to validate. I'm still getting the IO Exception (previously defined). Please assist. I think it has to do with the DTD definition but I'm not sure.

I agree. Here's the link:
subject: Struts and Vlidation
jQuery in Action, 3rd edition