Error Messages

Struts messages and Calyxo messages differ in that Calyxo messages may have a resource key and bundle name whereas Struts messages only have a key. Thus, when creating Struts action errors, the bundle "gets lost". To prevent from this, the validator plugin does the following:

If a Struts message has to be created from a Calyxo message with a bundle set, the plugin formats the message during validation and creates a Struts action message with key "", which takes the preformatted message string as an argument.

Therefore, to display validation error messages, you should either add the line

={0}

to your messages properties file, or check for messages with empty keys in your JSP and simply output their argument.

If you want to use Struts' <html:messages> tag to display your messages, you have to take the first option. Below is a JSP fragment which displays all messages using the struts.messages accessor provided by Calyxo Struts:

<c:set var="errors" scope="page"
  value="${calyxo.struts.messages['org.apache.struts.action.ERROR']}"/>
<c:if test="${!empty pageScope['errors']}">
  <c:set var="bundle" value="${calyxo.base.i18n.bundle['application']}"/>
  <ul>
    <c:forEach var="error" items="${errors}">
      <c:choose>
        <!-- formatted message (if you don't have line "={0}") -->
        <c:when test="${empty error.key}">
          <li>${error.values[0]}</li>
        </c:when>
        <!-- message without arguments -->
        <c:when test="${empty error.values}">
          <li>${bundle.message[error.key]}</li>
        </c:when>
        <!-- message with one or more arguments -->
        <c:otherwise>
          <li>${bundle.message[error.key][error.values]}</li>
        </c:otherwise>
      </c:choose>
    </c:forEach>
  </ul>				
</c:if>