views:

218

answers:

0

I'm sure this question is more related to spring MVC itself, not to the portlet part of spring MVC. I'm new to both of them.

I'm developing a portlet based on spring MVC portlet. I need to show a list of links and, when the user clicks on any of them, I get its ID in the controller and do some processing. There's the possibility that the processing throws an exception, and in this case I catch this exception and want to show to the user that the processing failed.

For the controller I'm extending AbstractCommandController and implementing the method handleAction(ActionRequest, ActionResponse, Object, BindException. To render, I'm using JSTL.

What I'm trying so far is a code like this:

    protected void handleAction(ActionRequest request, ActionResponse response,
        Object command, BindException exception) throws Exception {

    ViewCommand viewCommand = (ViewCommand)command;

    String id = viewCommand.getAid();

    try {
        service.executeOperation(id);
    } catch (Exception e) {
        exception.reject("errorCode");
        return;
    }
    // success
}

Then, to show the error in the page, I was trying something like this:

<c:out value="${status.errorMessage}"/>

or

<c:forEach items="${errors.globalErrors}" var="error">
    <div class="error">
        <spring:message code="${error.code}" />
    </div>
  </c:forEach>

or

    <c:if test="${not empty errors}" >
    I'm here
</c:if>

But it seems I can't get a reference to the errors object in the jsp.

What am I doing wrong?

I considered changing to SimpleFormController as there are many examples about this, but I think that the it should work with AbstractCommandController.

Thanks in advance!