At 7:13 PM +0100 4/17/05, David Easley wrote:
My form uses the Struts validator. One of its fields is 'required' and I
want the error message to show up alongside the field when the form is
redisplayed. There may also be general errors and I want these to be listed
at the top of the page. Problem is, the field  specific error (created by
the validator framework) gets displayed alongside the field (correctly) AND
as a general error at the top of the page! I don't understand this; the
error message must be associated with a field property otherwise it wouldn't
show up alongside the field, so why is it also being treated as a general
error?

When you ask a JSP tag (html:messages or html:errors) to iterate through errors without specifying a property, it iterates through all messages; basically, you are just guessing wrong as to its default behavior.


To get the behavior you want, one must specify as the "property" the String literal used for "global errors", that is: "org.apache.struts.action.GLOBAL_MESSAGE"

It would be good to extend those JSP tag implementations to have another attribute which basically meant "only show global messages" so that you wouldn't have to know that literal value. In fact, I just filed an enhancement ticket in Bugzilla about it:

http://issues.apache.org/bugzilla/show_bug.cgi?id=34489

I don't have time to write the patch right now, but as noted in the ticket, this would be a pretty easy one for someone interested in volunteering some time.

Joe


The relevant snippets from my code are below.

Any help gratefully received.

David
--

[-------- struts-config.xml --------]
<form-bean name="areaHierarchyForm"
  type="org.apache.struts.validator.DynaValidatorForm">
        <form-property name="name" type="java.lang.String"/>
        ...
</form-bean>
...
<action
                path="/area-hierarchy/submit"
                type="com.acme.UpdateAreaHierarchyAction"
                name="areaHierarchyForm"
                scope="session"
                validate="true"
                input="/AreaHierarchy.jsp">
         <forward name="continue" path="/AreaHierarchy.jsp"/>
         <forward name="success" path="/area-hierarchy/list.do"/>
</action>


[-------- validation.xml --------] <form name="areaHierarchyForm"> <field property="name" depends="required"> <arg0 key="areaHierarchyForm.name"/> </field> </form>


[-------- MessageResources.properties --------] areaHierarchyForm.name=Hierarchy Name


[-------- AreaHierarchy.jsp --------] ... <!-- #### General error messages #### --> <logic:messagesPresent> <span class="error"><bean:message key="errors.validation.header"/></span> <ul class="error"> <html:messages id="error"> <li><c:out value="${error}"/></li> </html:messages> </ul> </logic:messagesPresent>

<html:form action="/area-hierarchy/submit">
        <html:text styleId="name" property="name"/>
        <!-- #### Field specific error message #### -->
        <span class="error"><html:errors property="name"/></span>
...


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]


--
Joe Germuska [EMAIL PROTECTED] http://blog.germuska.com "Narrow minds are weapons made for mass destruction" -The Ex


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to