Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Validate errors are not being diplayed. Why?

 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im not sure what im doing wrong, but the errors (ie mandatory fields are left blank) are not being diplayed once the form is being validated.
Thank you for your time.
<action input="/HtmlFile.jsp" name="FileForm" path="/HtmlFile"
scope="session" type="ch12.HtmlFileAction" validate="true">
<forward name="default" path="/HtmlFile.jsp"/>
</action>
<html:html>
<body >
<html:errors/>
<html:form action="HtmlFile.do" enctype="multipart/form-data">

Item Type
<html:select name="HtmlFileForm" property="itemType">
<html ptions collection="itemlists" property="id" labelProperty="description"/>
</html:select>
<br/>
Item ID
<br/>
<html:text property="name"/>
<br/>
Thumbnail Image
<br/>
<html:file property="file"/>
<br/>
Price
<br/>
<html:text property="price"/>
<br />
<html:submit />
</html:form>
public class FileForm extends ActionForm{
private String submit;
.....

public ActionErrors validate( ActionMapping mapping, HttpServletRequest request )
{
ActionErrors errors = new ActionErrors();
if(getFile() ==null)
{
errors.add("file",new ActionError ("error.file.required"));
}
.....
if ( getPrice() == null || getPrice().length() < 1 )
{
errors.add("price",new ActionError("error.price.required"));
}

return errors;
}
 
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Check that you have your message resources file (i.e. ApplicationResources.properties) specified in your struts config.
2) Check that the file is there, where you expect it to be.
3) Check that the specified message key is present in the file.
1 I can't help with.
2 Try adding the following to your ApplicationResources.properties file and restarting your app, then rerunning your test that should display errors...
# html:errors tag configuration ------------------------------------------
errors.header=<ul>
errors.prefix=<li>
errors.suffix=</li>
errors.footer=</ul>
If your file is loaded properly, your messages will now be in a bulleted list. If you see
(bullet)
(bullet)
Or something similar, your problem is likely with #3.
 
Let me tell you a story about a man named Jed. He made this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic