History | Log In     View a printable version of the current page. Get help!  
Issue Details [XML]

Key: BPM-245
Type: Bug Bug
Status: Closed Closed
Resolution: Not an issue
Priority: Critical Critical
Assignee: Wouter Zoons
Reporter: Bobby Peterson
Votes: (View)
Watchers: (View)
Operations

If you were logged in you would be able to see more operations.
Bpm4Struts Cartridge

saveErrorMessages don't work anymore

Created: 16/Aug/05 05:30 PM   Updated: 19/Aug/05 06:58 AM
Component/s: None
Affects Version/s: 3.1M1
Fix Version/s: None

Environment: JDK 1.5, Struts 1.2.7, Windows XP Pro


 Description   
After upgrading to 3.1 I have had many problems with the error messages and validation. The custom validation is still not working. In the controller methods I call saveErrorMessage given it the request and a valid message key. The error is saved into the session but the flow of the application continues to go to the next action state, JSP which causes major problems because an error has occured.
With some investigation I found that the code generated in 3.0 wrapped the next call in an if block like the following:
if (this.errorsNotPresent(request))
{
    forward = _retrieveData(mapping, form, request, response);
}

in 3.1 the code looks like:
forward = _retrieveData(mapping, form, request, response);

Is there a reason this change was made? Did I not set a property? If so, shouldn't the old behavior be the default?
Thanks for the help or the fix.




The complete methods are below:
############################################### 3.0 ###########################################
ActionForward forward = null;

private ActionForward _detailsOk(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
    {
        ActionForward forward = null;

final org.apache.struts.action.ActionMessages errors = this.getExceptionHandlerErrors(request);
        try
        {
            if (this.errorsNotPresent(request))
            {
                PlanControllerFactory.getPlanControllerInstance().saveDetails(mapping, DetailsSummarySaveDetailsFormImpl)form, request, response);
            }
            if (this.errorsNotPresent(request))
            {
                forward = _retrieveData(mapping, form, request, response);
            }
        }
        catch (Exception ex)
        {
            final String messageKey = org.andromda.presentation.bpm4struts.PatternMatchingExceptionHandler.instance().handleException(ex);
            errors.add(org.apache.struts.action.ActionMessages.GLOBAL_MESSAGE, new org.apache.struts.action.ActionMessage(messageKey));
        }
        finally
        {
        }
        if (!errors.isEmpty())
        {
            forward = mapping.getInputForward();
        }
        return forward;
    }



###################################### 3.1 #########################################################

private org.apache.struts.action.ActionForward _detailsOk(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.lang.Exception
    {
        org.apache.struts.action.ActionForward forward = null;

try
        {
            com.sys.uswdss.web.planning.plan.PlanControllerFactory.getPlanControllerInstance().saveDetails(mapping, (DetailsSummarySaveDetailsFormImpl)form, request, response);
            forward = _retrieveData(mapping, form, request, response);
        }
        catch (java.lang.Exception exception)
        {
            final java.lang.String messageKey = org.andromda.presentation.bpm4struts.PatternMatchingExceptionHandler.instance().handleException(exception);
            com.sys.uswdss.web.planning.plan.PlanControllerFactory.getPlanControllerInstance().saveErrorMessage(request, messageKey);
            throw exception;
        }


        return forward;
    }



 All   Comments   Change History      Sort Order:
Comment by Wouter Zoons [16/Aug/05 05:57 PM]
I've been working on this part, seems I cut out too much of the code. I refactored some of the action code into an exception handler.

I'll take care of this issue right away

Comment by Wouter Zoons [16/Aug/05 06:08 PM]
could you try again with the very latest CVS snapshot ? the 3.1 code you pasted seems to contain stuff from at least a few days old

the pattern exception handler should not be called anymore from the actions, this is now handled declaratively via struts-config.xml

don't hesitate to send me your project and a small description on how to reproduce, if the project is very simple you can even attach it to this issue

Comment by Bobby Peterson [17/Aug/05 12:10 PM]
I couldn't try yesterday, but I did try this morning, and I still get the same results. It continues on the the next JSP. The generated code has changed a little, but I don't see how this code should prevent it from going on to the next state in the flow. I definitely don't see how the next method is prevented from being called. I am not throwing an exception, just calling saveErrorMessage. Should that change?
sorry I can't attach the project, we have 21 models and a few thousands files. In the code below and in the model, we want to call saveDetails then if we had no errors during the save we want to go on to the next step and retrieveData for display to the user. Currently when we have errors it still tries to retrieveData (causing problems) and shows the error from the save on that new page. This can be reproduced throughout our application. Thanks again.


New Generated code:
 private org.apache.struts.action.ActionForward _detailsOk(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.lang.Exception
    {
        org.apache.struts.action.ActionForward forward = null;
        com.sys.uswdss.web.planning.plan.PlanControllerFactory.getPlanControllerInstance().saveDetails(mapping, (DetailsSummarySaveDetailsFormImpl)form, request, response);
        forward = _retrieveData(mapping, form, request, response);

return forward;
    }

Comment by Wouter Zoons [17/Aug/05 12:34 PM]
are you saying you or /only/ saving the exception message ? you're /not/ throwing an exception ? in that case the behavior is normal

some people want to forward error messages in specific cases, without having to deal with the handling of exceptions

you should just throw an exception and let Struts handle it, the default behavior is to return to the input page

if saving an error message made the webapp return to the input page in one of the earlier AndroMDA versions than that was a bug

Comment by Bobby Peterson [17/Aug/05 12:45 PM]
I'm saying that I am calling the method saveErrorMessage that is generated in the Controller abstract class. It is below. When called it took the use back to the page they came from, while a call to saveWarningMessage took the user to the next page but gave a warning. So has this functionality been removed?

protected final void saveErrorMessage(javax.servlet.http.HttpServletRequest request, java.lang.String message, java.lang.String[] arguments)
    {
        final javax.servlet.http.HttpSession session = request.getSession();

// we explicitely store and retrieve the messages from the session, as opposed to using
        // Action.saveMessages because this constroller does not have access to the current Action instance
        org.apache.struts.action.ActionMessages messages = (org.apache.struts.action.ActionMessages)session.getAttribute(org.apache.struts.Globals.MESSAGE_KEY);
        if (messages == null)
        {
            messages = new org.apache.struts.action.ActionMessages();
            session.setAttribute(org.apache.struts.Globals.MESSAGE_KEY, messages);
        }
        messages.add("org.andromda.bpm4struts.errormessages", new org.apache.struts.action.ActionMessage(message, arguments));
    }

Comment by Wouter Zoons [17/Aug/05 12:49 PM]
well, that wasn't a feature .. that was a bug

it has never been the purpose to assume exceptional (pun intended) behavior when saving messages, saving messages only does exactly that

sorry for the confusion

Comment by Bobby Peterson [17/Aug/05 02:06 PM]
From the code that was generated in the 3.0 example above it looks like it was pretty explicit to be a bug but if you say that's what it was I guess I have to believe you. But I like the way it worked when it was a bug.
 In the current way, to have multiple errors displayed I need to save them all and then find the last place in my code before the generated code is going to make the next method call and throw an exception, (but I don't want the exception to be displayed as an because it is just there because it is now required.)

Comment by Wouter Zoons [17/Aug/05 02:25 PM]
Well, the only thing I can tell you is that I never-ever intended this to be the behavior. If you want to go back to the input page after all messages are saved, and you are sure you want to do this without throwing an exception, then why not simply model a transition back into the source page ?

The solution as it exists today is complete:

1. exceptions can be directed using transitions carrying the <<Exception>> stereotype
2. 3 types of messages can be recorded automatically (error, success and warning), just put the proper tagged value on the corresponding transition
3. you can call these methods yourself if you like, without any side-effects such as exception handling etc...
4. use regular transitions to direct the process flow into a certain direction

the case you gave me does not fall into a category that cannot be solved with these items, unless I have not well understood the issue you're facing

Comment by Wouter Zoons [19/Aug/05 06:58 AM]
since there have been no more follow-ups I've decided to close this issue