File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes html:errors displayed before form is submitted Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "html:errors displayed before form is submitted" Watch "html:errors displayed before form is submitted" New topic

html:errors displayed before form is submitted

Toni Heightland

Joined: Oct 25, 2005
Posts: 7

I am new to struts, and while I've found the solutions to most of my problems, this one has had me stumped for days.

The form validation errors are displayed when the form is initially displayed, so before the user has even had an opportunity to enter data that would need to be validated.
I've completed a test struts application, and I do not have this problem in the test app.

I don't think it makes a difference, but in this application, I'm using LookupDispatchAction, instead of Action. Aside from that difference, the only significant difference is that my current app uses filters to set up some application support.

Here is the relevant part of my struts-config.xml:


type="edu.ohio.struts.formBeans.ManageContactForm" />



<!-- Default "Welcome" action -->
<!-- Forwards to Welcome.jsp -->

<action path="/ManageInformation"
input="/pages/ManageContactInformation.jsp" >
<forward name="show_result" path="/pages/Welcome.jsp" />

Here is the jsp that calls the form:

<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>

<html:html locale="true">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><bean:message key="welcome.title"/></title>
<h1><bean:message key="welcome.heading"/></h3>
<p><bean:message key="welcome.message"/></p>
<html:link page="/">Add Contact</html:link>
<html:link page="/">Search Contacts </html:link>
<div id="footer">

And here is the form that's showing the errors before data has been entered:
(I've cut a bunch of it out b/c it is a long form, but hopefully left enough relavent information)...

<!-- <title>${actionType.title}</title>-->
<title><bean:message key="add.title" /></title>


<h1><bean:message key="add.heading" /></h1>
<html:form action="" method="post" >

<html:errors property="contactType" />
<fieldset> <legend>Contact Type </legend>
<html:radio property="contactType" value="newspaper"/>Newspaper
<html:radio property="contactType" value="legislator" />Legislator
<h2>Contact Information</h2>
<html:text property="name" value=""size="26" maxlength="25"/>
</label> <html:errors property="name" />
<label>Contact Person:
<html:text property="contactPerson" value="" size="26" maxlength="25"/>
</label> <html:errors property="contactPerson" />

<html:submit property="action"> <bean:message key="button.add" /> </html:submit>
<html:cancel value="Cancel"/>

Can anyone help me with this?

Thanks in advance!
[ November 11, 2005: Message edited by: Toni Heightland ]
Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

What address do you see in the browser when the problem occurs? Do you see Welcome.jsp or

A good workman is known by his tools.
Toni Heightland

Joined: Oct 25, 2005
Posts: 7

Thanks a ton for taking the time to assist me with this problem! I'm still searching for a solution!
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
I am new to struts, but I believe the problem is a logic issue. I am assuming the link below is contained in the welcome.jsp page.

So when the link above is clicked a new ActionForm is created, based on your configuration that would be object "ManageContactForm", this object should be populated with the parameters from the request object, but since there were no parameters passed to the ActionForm, the Action object created from the class "edu.ohio.struts.action.ManageContactAction", would return invalid information.

Basically your ActionForm object was created without any information and then passed to the Action object for processing. You need to capture the information from the Form first, then pass it to the ActionForm.

My suggestion is to create a global forwards and call it something like:

And then change the link in the welcome.jsp to :

Like I said, I am new, so maybe this can share some light on the situation.
Toni Heightland

Joined: Oct 25, 2005
Posts: 7
That fixed it! I had an idea of what was happening, but I wasn't sure how to fix it. Thanks for the example. I am very grateful.
I agree. Here's the link:
subject: html:errors displayed before form is submitted
It's not a secret anymore!