aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "html:errors displayed before form is submitted" Watch "html:errors displayed before form is submitted" New topic
Author

html:errors displayed before form is submitted

Toni Heightland
Greenhorn

Joined: Oct 25, 2005
Posts: 7
Hi,

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:

<form-beans>

<form-bean
name="ManageContactForm"
type="edu.ohio.struts.formBeans.ManageContactForm" />

</form-beans>

<global-forwards>
<forward
name="welcome"
path="/Welcome.do"/>
</global-forwards>

<action-mappings>
<!-- Default "Welcome" action -->
<!-- Forwards to Welcome.jsp -->
<action
path="/Welcome"
forward="/pages/Welcome.jsp"/>

<action path="/ManageInformation"
name="ManageContactForm"
scope="request"
type="edu.ohio.struts.action.ManageContactAction"
validate="true"
input="/pages/ManageContactInformation.jsp" >
<forward name="show_result" path="/pages/Welcome.jsp" />
</action>
[...]

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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><bean:message key="welcome.title"/></title>
<html:base/>
</head>
<body>
<h1><bean:message key="welcome.heading"/></h3>
<p><bean:message key="welcome.message"/></p>
<ul>
<li>
<html:link page="/ManageInformation.do">Add Contact</html:link>
</li>
<li>
<html:link page="/Search.do">Search Contacts </html:link>
</li>
</ul>
<div id="footer">
</div>
</body>
</html:html>


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)...

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

</head>

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


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

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

Can anyone help me with this?

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

Joined: Feb 05, 2003
Posts: 4727

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


A good workman is known by his tools.
Toni Heightland
Greenhorn

Joined: Oct 25, 2005
Posts: 7
ManageInformation.do

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
Greenhorn

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: http://aspose.com/file-tools
 
subject: html:errors displayed before form is submitted