Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-11-2007, 02:53 AM
Member
 
Join Date: Apr 2007
Location: Pennsylvania,USA
Posts: 46
sandor is on a distinguished road
error message on jsp
Am trying to learn struts...not easy.
Anyway, I want to display an error message on a page if the user forgets to enter a field. I figured out how to do that with the validate() method in the ActionForm. OK, but now I want to make the error show up if they did something the database does not like. So I am off into the Action now.
Lets say they want to order some widgets, and there were some in the inventory when the screen came up, but they looked at it a while, they went and had a cup of coffee, and when they got back and clicked the "order" button the application goes out to the database and lo and behold, there are no more widgets left. So how do I deal with this and show that nice little error message on the same screen. "sorry, the last widget has been sold".
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-11-2007, 03:10 AM
Member
 
Join Date: Apr 2007
Location: Indiana
Posts: 84
pegitha is on a distinguished road
Send a message via Skype™ to pegitha
Here is how I normally handle something like this:
Code:
public ActionForward getWidgets(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ActionMessages errors = new ActionMessages(); ActionForward forward = new ActionForward(); try { List widgets=WidgetManager.getWidgets(); forward = mapping.findForward("gotthem"); } catch (NoWidgetsFoundException e) { errors.add("noWidgetsLeftError", new ActionMessage("error.noWidgetsLeftError")); saveErrors(request, errors); } return (forward); }
My WidgetManager.getWidgets() throws a NoWidgetsFoundException. That is caught in the Action and then you create a new ActionMessage. The message that is going to be displayed is still in the ApplicationResource.properties file, just like the errors you collect in the Form.validate() method.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please wail Message in jsp amar.java JavaServer Pages (JSP) and JSTL 1 04-02-2008 01:29 PM
java error message baileyr New To Java 2 01-23-2008 04:47 AM
Strange error message "Source not found" ppayal Eclipse 0 11-25-2007 07:19 PM
Help with error message when running JAR via HTML file Simmy AWT / Swing 7 08-12-2007 04:47 PM
About bean:message yuchuang Web Frameworks 1 05-03-2007 05:50 PM


All times are GMT +3. The time now is 07:48 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org