• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

blank page returned from validate

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 (/testing.do), 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.


***************************************************
struts-config.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>

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

<action-mappings>
<action path="/testing"
type="com.x.struts.InfoAction"
name="infoForm"
scope="request"
validate="true"
input="/Submit1.jsp">
</action>
</action-mappings>
<message-resources parameter="/WEB-INF/eng_messages.properties"/>
</struts-config>


********************************************************************
Submit1.jsp

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


***************************************************************
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"));
}
if(!validate.email(request.getParameter("Email"))){
confirm += 1;
messages.add(messages.GLOBAL_MESSAGE, new org.apache.struts.action.ActionMessage("validate.Email.incomplete"));
}


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

}


*********************************************************************
eng_messages.properties 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
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
It looks like it's time for me to write you a reality check! Or maybe a tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic