Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

html:errors displayed before form is submitted

 
Toni Heightland
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What address do you see in the browser when the problem occurs? Do you see Welcome.jsp or ManageInformation.do?
 
Toni Heightland
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic