• 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

problem with html:errors

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am using the following code to display errors in my jsp. In my action class:
-----
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("Error1"));
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("Error2"));
----
saveErrors(request, errors);
forward = mapping.findForward("success");

and in my jsp i am using <html:errors/> .
I am not using any action form. I just want to display some business errors that occur in my action class. But this doesnot work.

Can any one tell me whats wrong in this?

Thanks in advance
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this example, "Error1" and "Error2" must exist as message keys in your ApplicationResources.properties file. If you have the following entries;

Error1=This is the text for error 1
Error2=This is the text for error 2

Your example should show:

* This is the text for error 1
* This is the text for error 2
 
Srini Nivas
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks you very much for the information and that works now......but I would like to know if there is any other way around without using the resource file do display a general message given in the code directly???
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Messages do accept parameters. So, if you really want to create the message at run time, you can just do this:

ApplicationResources.properties
Error1={0}

Action class
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("Error1", "This is now the new error message"));

Or you can do something like this:

ApplicationResources.properties
Error1=Customer {0} is already in the database.

Action class
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("Error1", "John Doe"));
 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alternatively, if you want to keep your hands absolutely clean off the .properties file... then you could simply set attributes in your request object and in your JSP use the <logic:present> tags to display error messages if the corresponding request attribute is present in the request.

In your Action class:
request.setAttribute("sErrorMsg", "y");

In your JSP:
<logic:present name="sErrorMsg" value="y" scope="request">
** this is the txt for error message **
</logic:present>
[ February 16, 2006: Message edited by: Anirvan Majumdar ]
 
Srini Nivas
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your help.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am having similar problem , please suggest me,

Code at ActionForm:

if(totaltenderAwdAmtSGD.compareTo(finLimitAmt) > 0)
{
ActionErrors actionErrors=new ActionErrors();
actionErrors.add(ActionErrors.GLOBAL_ERROR,new ActionError("error.tender.finAmt.chk.msg"));
Log.out.debug(" finLimitAmtfinLimitAmt 0000: "+actionErrors.isEmpty());

if (!actionErrors.isEmpty()) {
saveErrors(req,actionErrors);
Log.out.debug(" finLimitAmtfinLimitAmt 1111: "+finLimitAmt);

}

Log.out.debug(" finLimitAmtfinLimitAmt 2222: "+finLimitAmt);
strForward = "awardConfirmItem";

}


Am getting all the prints,

entry at ApplicationProperties.properties

error.tender.finAmt.chk.msg=<li>You may want to reduce the Total Awarded Amount as it exceeds selected Approving/ Verifyin Officer financial limit of approval.</li>

and at JSP

<td><html:errors bundle="webitt"/></td></tr>

Still am unable to get error message, please suggest me on this.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try removing bundle="webitt" from your <html:errors /> tag.

Also, make sure that the actionErrors variable is getting returned by the ActionForm's validate() method.
 
SuprajaY Yasoda
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for the reply, validate method of my ActionFomm returns actionErros, but still am unable to display message. I tried removing webitt(folder in which my ApplicationResources.properties file is residing.)
 
reply
    Bookmark Topic Watch Topic
  • New Topic