Results 1 to 2 of 2
  1. #1
    sandor is offline Member
    Join Date
    Apr 2007
    Location
    Pennsylvania,USA
    Posts
    45
    Rep Power
    0

    Default 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".

  2. #2
    pegitha is offline Member
    Join Date
    Apr 2007
    Location
    Indiana
    Posts
    83
    Rep Power
    0

    Default

    Here is how I normally handle something like this:
    Java 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.

Similar Threads

  1. Please wail Message in jsp
    By amar.java in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-02-2008, 01:29 PM
  2. java error message
    By baileyr in forum New To Java
    Replies: 2
    Last Post: 01-23-2008, 04:47 AM
  3. Strange error message "Source not found"
    By ppayal in forum Eclipse
    Replies: 0
    Last Post: 11-25-2007, 07:19 PM
  4. Replies: 7
    Last Post: 08-12-2007, 04:47 PM
  5. About bean:message
    By yuchuang in forum Web Frameworks
    Replies: 1
    Last Post: 05-03-2007, 05:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •