You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mark Songhurst <ms...@messagelabs.com> on 2004/10/05 15:51:10 UTC

How to iterate through Validator errors only in JSP?

Hi

This is rather wordy, but a probably a simple question, so please bear
with me! All using Struts 1.2

I have an ActionForward execute method which creates and populates an
ActionMessages object. The ActionMessage objects that I populate it with
are given the property of "violation", and the key
"error.wizard.workflow.violation". This works fine - Code snippet below:

------------------------------------------------------------------------
-----------
ActionMessages errors = new ActionMessages();
if (null != WorkflowUtils.getNextStateViolationAction(request))
{
  errors.add("violation", new
ActionMessage("error.wizard.workflow.violation"));
  saveErrors(request, errors);
}
------------------------------------------------------------------------
-----------

To display these contents of this ActionMessages object, I use the
following snippet of code (which also works fine):

------------------------------------------------------------------------
-----------
<p>
  <logic:messagesPresent property="violation">
    <bean:message key="wizardForm.violation.errors.header"/>
    <ul>
      <html:messages id="violation">
        <li><bean:write name="violation"/></li>
      </html:messages>
     </ul><hr>
  </logic:messagesPresent>
</p>
------------------------------------------------------------------------
-----------

My code uses an ValidatorForm to gain the use of the Struts Validator.
This (again!) works fine, but what I'm stuck on is how to display the
errors only found by the Validator - not those errors which I have added
to my ActionMessages object (ie, not those with the property of
"violation").

If I use the following code snippet in my JSP, then messages from both
the Validator and my ActionMessages object are written to the page in
the same place (which is not what I want):

------------------------------------------------------------------------
-----------
<p>
  <logic:messagesPresent>
    <bean:message key="wizardForm.validation.errors.header"/>
    <ul>
      <html:messages id="violation">
        <li><bean:write name="violation"/></li>
      </html:messages>
     </ul><hr>
  </logic:messagesPresent>
</p>
------------------------------------------------------------------------
-----------

I guess what would be ideal is a property= value for the Struts
Validator messages, but I can't seem to find one referenced or online.

Please could someone suggest a solution, or point me at online resource
which would answer my query?

Many Thanks,
Mark.


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org