Announcement Announcement Module
Collapse
No announcement yet.
Access Errors object in MultiAction Method Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 02:27 PM.

  • #2
    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.

    Comment


    • #3
      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>
      .....

      Comment

      Working...
      X