Results 1 to 3 of 3

Thread: Access Errors object in MultiAction Method

  1. #1
    Join Date
    Sep 2006
    Posts
    5

    Default Access Errors object in MultiAction Method

    Hi,

    I would like to return a generic error message to my view. One that is not associated with any of the fields on the view. Much like that specified at the end of the thread found here -> http://forum.springsource.org/showth...ght=error+path

    I have a class that extends MultiAction and my method looks like so:

    Code:
    public Event idQuestionsCorrect(RequestContext context) {
    		AnswerIdQuestionsForm form = (AnswerIdQuestionsForm) context.getFlowScope()
    			.get("answerIdQuestionsForm");
    		if(service.areAnswersCorrect(
    				(String)context.getFlowScope().get("username"),
    				form.getLastName(),
    				form.getBirthdate(),
    				form.getIdNumber())) {
    			return yes();
    		}
    		else {
    			context.getMessageContext().addMessage(
                             // WANT TO ADD THE GENERIC MESSAGE HERE. PLEASE HELP!
    			return no();
    		}
    	}
    My question is, how in the code above do I get an Errors object so that I can add a new ObjectError?

    Thanks in advance.
    Last edited by golfbrew; Feb 26th, 2010 at 02:27 PM.

  2. #2
    Join Date
    Nov 2008
    Posts
    742

    Default

    You'll be working with the MessageContext and MessageBuilder classes, so you might want to look them up in the SWF Javadoc.

    I think you'll find this section of the SWF reference guide helpful.

    The Adding Plain Text Messages section at the top should be want you want. Just don't use the "source()" method in the builder when creating your message.

  3. #3
    Join Date
    Sep 2006
    Posts
    5

    Default Working now.

    Thanks for the fast reply. I have it working now. Please let me know if I missed anything. Seems too simple so I must have done something wrong For the record:

    Source Code:
    Code:
    	public Event idQuestionsCorrect(RequestContext context) {
    		AnswerIdQuestionsForm form = (AnswerIdQuestionsForm) context.getFlowScope()
    			.get("answerIdQuestionsForm");
    		if(service.areAnswersCorrect(
    				(String)context.getFlowScope().get("username"),
    				form.getLastName(),
    				form.getBirthdate(),
    				form.getIdNumber())) {
    			return yes();
    		}
    		else {
    			context.getMessageContext().addMessage(
    					new MessageBuilder().error()
                                            .code("error.answerIdQuestionsForm.failed")
                                            .build());
    			return no();
    		}
    	}
    and my view has the following:
    Code:
    ....
    	    <tr>
    	    	<td colspan="3" class="error">
    	    		<form:errors />
    	    	</td>
    	    </tr>
    .....

Tags for this Thread

Posting Permissions

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