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

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "blank page returned from validate" Watch "blank page returned from validate" New topic

blank page returned from validate

Billy Bob

Joined: Apr 05, 2005
Posts: 21
I'll preface this by saying that i am extremely new at using struts. Finally got around the various error and display issues and now i'm just not getting anything. when i submit the form i get a blank page (/, i was under the impression that it would return to the page indicated in the input parameter of the action-mapping. The following is the code that i'm using, any input would be appreciated.


<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "">

<form-bean name="infoForm" type="com.x.struts.InfoForm"/>

<action path="/testing"
<message-resources parameter="/WEB-INF/"/>


<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-form.tld" prefix="form" %>
<title>Struts Number One Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%@ page language="java"%>
<html:form action="/" focus="FirstName">
<table width="500" border="0" cellspacing="0" cellpadding="5">
<td>First Name:</td>
<td><html:text property="firstName"/></td>
<td>Last Name:</td>
<td><html:text property="lastName"/></td>
<td><html:text property="address"/></td>
<td>Address 2:</td>
<td><html:text property="address2"/></td>
<td><html:text property="city"/></td>
<td><html:text property="provState"/></td>
<td><html:text property="country"/></td>
<td><html:text property="postalZip"/></td>
<td><html:text property="phone"/></td>
<td><html:text property="email"/></td>
<td colspan="2"><html:submit value="submit"/></td>

validate method of the com.x.struts.InfoForm bean

public org.apache.struts.action.ActionErrors validate(org.apache.struts.action.ActionMapping mapping, javax.servlet.ServletRequest request) {
int confirm = 0;
com.x.validation.Validate validate = new com.x.validation.Validate();
org.apache.struts.action.ActionErrors messages = new org.apache.struts.action.ActionErrors();

if(request.getParameter("FirstName").trim().length() == 0){
confirm += 1;
messages.add(messages.GLOBAL_MESSAGE, new org.apache.struts.action.ActionMessage("validate.FirstName.incomplete"));
if(request.getParameter("LastName").trim().length() == 0){
confirm += 1;
messages.add(messages.GLOBAL_MESSAGE, new org.apache.struts.action.ActionMessage("validate.LastName.incomplete"));
if(request.getParameter("Address").trim().length() == 0){
confirm += 1;
messages.add(messages.GLOBAL_MESSAGE, new org.apache.struts.action.ActionMessage("validate.Address.incomplete"));
if(request.getParameter("Phone").trim().length() == 0){
confirm += 1;
messages.add(messages.GLOBAL_MESSAGE, new org.apache.struts.action.ActionMessage("validate.Phone.incomplete"));
confirm += 1;
messages.add(messages.GLOBAL_MESSAGE, new org.apache.struts.action.ActionMessage("validate.Email.incomplete"));

if(confirm > 0){
return messages;
} else {
return null;


********************************************************************* file

validate.FirstName.incomplete=<LI>Please input your first name.</LI>
validate.LastName.incomplete=<LI>Please input your last name.</LI>
validate.Address.incomplete=<LI>Please input your Address.</LI>
validate.Phone.incomplete=<LI>Please input your Phone.</LI>
validate.Email.incomplete=<LI>Please input a valid email address.</LI>


thanks for your help
Billy Bob

Joined: Apr 05, 2005
Posts: 21
ok... figured it out... if you are going to override validate make sure you aren't being a moron and overriding the wrong one... override the one that takes javax.servlet.http.HttpServlet as an argument. Secondly, something that really irritated me initially, your form elements must start with a lower case character and if you are using a ActionForm it will automatically try to compare parameters (introspection) by prefacing your form elements with get/set and changing your first character to uppercase... as a result make certain that you aren't thinking of that in your validate and just focus on the form element names (i didn't change them when i changed the forms)....

hope this might help someone...
I agree. Here's the link:
subject: blank page returned from validate
jQuery in Action, 3rd edition