You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Erik Weber <er...@mindspring.com> on 2004/07/29 09:47:11 UTC

Retrieving specific form validation error messages

In a JSP containing a form, what is the easiest way to see if a form 
validation error message exists for a particular, say, html:text field, 
when that page is processing after form validation has failed? For 
example, what if you wanted to present the messages field by field 
instead of all together at the top of the page? I assume the error 
messages are keyed according to the value of the "property" attribute 
for each field, or something similar?

Thanks,
Erik

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


Re: Retrieving specific form validation error messages

Posted by Kishore Senji <ks...@gmail.com>.
You could do something like this

<td><html:text property="login"/></td><td class="error"><html:errors
property="login"/></td>
<td><html:password property="password" redisplay="false"/></td><td
class="error"><html:errors property="password"/></td>

Thanks,
Kishore Senji.

On Thu, 29 Jul 2004 14:18:25 -0400, Erik Weber <er...@mindspring.com> wrote:
> Thanks Niall.
> 
> Now, what I need is to change the style of the prompt text beside the
> field, not the field itself, or else perhaps the td that houses both the
> prompt and the input. But, you have given me an idea . . . Perhaps I
> could extend the bean:message tag to act in a similar way? I would
> appreciate knowing if you think that is sensible.
> 
> I'll check out the bug report.
> 
> Thanks,
> Erik
> 
> 
> 
> 
> Niall Pemberton wrote:
> 
> >Theres an open bugzilla ticket requesting this kind of feature:
> >
> >   http://issues.apache.org/bugzilla/show_bug.cgi?id=20784
> >
> >Haven't really had time to look at it, but it has patches attached.
> >
> >I also posted an extension to the <html:text> tag on my web site which
> >highlights error fields.
> >
> >http://www.niallp.pwp.blueyonder.co.uk/#errortag
> >
> >Niall
> >
> >----- Original Message -----
> >From: "Erik Weber" <er...@mindspring.com>
> >To: "Struts Users Mailing List" <us...@struts.apache.org>
> >Sent: Thursday, July 29, 2004 10:10 AM
> >Subject: Re: Retrieving specific form validation error messages
> >
> >
> >
> >
> >>This is what I came up with:
> >>
> >><c:set var="foo" value="valueA"/>
> >><logic:messagesPresent name="org.apache.struts.action.ERROR"
> >>property="currentField">
> >><c:set var="foo" value="valueB"/>
> >></logic:messagesPresent>
> >>. . . render the prompt for currentField, placing <c:out
> >>value="${foo}"/> where necessary (this could be a css class or font
> >>color, etc.) , , ,
> >>
> >>I am doing this for each field. Please let me know if there is a better
> >>
> >>
> >way.
> >
> >
> >>Thanks,
> >>Erik
> >>
> >>
> >>
> >>Erik Weber wrote:
> >>
> >>
> >>
> >>>I see that the ActionErrors object is stored as a request attribute
> >>>under the key "org.apache.struts.action.ERROR".
> >>>
> >>>I would like to set a different CSS class for each <td> containing a
> >>>field that has a property that is keyed in the ActionErrors instance.
> >>>In pseudocode:
> >>>
> >>>begin "username" field;
> >>>if (ActionErrors instance exists and ActionErrors instance contains
> >>>any ActionErrors for the "username" property) {
> >>>open td with class set to "style B";
> >>>print prompt for username field;
> >>>print username field;
> >>>close td;
> >>>}
> >>>else {
> >>>open td with class set to "style A";
> >>>print prompt for username field;
> >>>print username field;
> >>>close td;
> >>>}
> >>>
> >>>. . . and so on, for each field. This seemingly could get to be a lot
> >>>of code. Any Struts/JSTL tag tricks I can use?
> >>>
> >>>
> >>>Thanks,
> >>>Erik
> >>>
> >>>
> >>>
> >>>
> >>>Erik Weber wrote:
> >>>
> >>>
> >>>
> >>>>In a JSP containing a form, what is the easiest way to see if a form
> >>>>validation error message exists for a particular, say, html:text
> >>>>field, when that page is processing after form validation has failed?
> >>>>For example, what if you wanted to present the messages field by
> >>>>field instead of all together at the top of the page? I assume the
> >>>>error messages are keyed according to the value of the "property"
> >>>>attribute for each field, or something similar?
> >>>>
> >>>>Thanks,
> >>>>Erik
> >>>>
> >>>>---------------------------------------------------------------------
> >>>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>>For additional commands, e-mail: user-help@struts.apache.org
> >>>>
> >>>>
> >>>>
> >>>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>For additional commands, e-mail: user-help@struts.apache.org
> >>>
> >>>
> >>>
> >>>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >>
> >>
> >>
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

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


Re: Retrieving specific form validation error messages

Posted by Erik Weber <er...@mindspring.com>.
Thanks Niall.

Now, what I need is to change the style of the prompt text beside the 
field, not the field itself, or else perhaps the td that houses both the 
prompt and the input. But, you have given me an idea . . . Perhaps I 
could extend the bean:message tag to act in a similar way? I would 
appreciate knowing if you think that is sensible.

I'll check out the bug report.

Thanks,
Erik



Niall Pemberton wrote:

>Theres an open bugzilla ticket requesting this kind of feature:
>
>   http://issues.apache.org/bugzilla/show_bug.cgi?id=20784
>
>Haven't really had time to look at it, but it has patches attached.
>
>I also posted an extension to the <html:text> tag on my web site which
>highlights error fields.
>
>http://www.niallp.pwp.blueyonder.co.uk/#errortag
>
>Niall
>
>----- Original Message ----- 
>From: "Erik Weber" <er...@mindspring.com>
>To: "Struts Users Mailing List" <us...@struts.apache.org>
>Sent: Thursday, July 29, 2004 10:10 AM
>Subject: Re: Retrieving specific form validation error messages
>
>
>  
>
>>This is what I came up with:
>>
>><c:set var="foo" value="valueA"/>
>><logic:messagesPresent name="org.apache.struts.action.ERROR"
>>property="currentField">
>><c:set var="foo" value="valueB"/>
>></logic:messagesPresent>
>>. . . render the prompt for currentField, placing <c:out
>>value="${foo}"/> where necessary (this could be a css class or font
>>color, etc.) , , ,
>>
>>I am doing this for each field. Please let me know if there is a better
>>    
>>
>way.
>  
>
>>Thanks,
>>Erik
>>
>>
>>
>>Erik Weber wrote:
>>
>>    
>>
>>>I see that the ActionErrors object is stored as a request attribute
>>>under the key "org.apache.struts.action.ERROR".
>>>
>>>I would like to set a different CSS class for each <td> containing a
>>>field that has a property that is keyed in the ActionErrors instance.
>>>In pseudocode:
>>>
>>>begin "username" field;
>>>if (ActionErrors instance exists and ActionErrors instance contains
>>>any ActionErrors for the "username" property) {
>>>open td with class set to "style B";
>>>print prompt for username field;
>>>print username field;
>>>close td;
>>>}
>>>else {
>>>open td with class set to "style A";
>>>print prompt for username field;
>>>print username field;
>>>close td;
>>>}
>>>
>>>. . . and so on, for each field. This seemingly could get to be a lot
>>>of code. Any Struts/JSTL tag tricks I can use?
>>>
>>>
>>>Thanks,
>>>Erik
>>>
>>>
>>>
>>>
>>>Erik Weber wrote:
>>>
>>>      
>>>
>>>>In a JSP containing a form, what is the easiest way to see if a form
>>>>validation error message exists for a particular, say, html:text
>>>>field, when that page is processing after form validation has failed?
>>>>For example, what if you wanted to present the messages field by
>>>>field instead of all together at the top of the page? I assume the
>>>>error messages are keyed according to the value of the "property"
>>>>attribute for each field, or something similar?
>>>>
>>>>Thanks,
>>>>Erik
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>>        
>>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>      
>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>>    
>>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>  
>

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


Re: Retrieving specific form validation error messages

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
Theres an open bugzilla ticket requesting this kind of feature:

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

Haven't really had time to look at it, but it has patches attached.

I also posted an extension to the <html:text> tag on my web site which
highlights error fields.

http://www.niallp.pwp.blueyonder.co.uk/#errortag

Niall

----- Original Message ----- 
From: "Erik Weber" <er...@mindspring.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Thursday, July 29, 2004 10:10 AM
Subject: Re: Retrieving specific form validation error messages


> This is what I came up with:
>
> <c:set var="foo" value="valueA"/>
> <logic:messagesPresent name="org.apache.struts.action.ERROR"
> property="currentField">
> <c:set var="foo" value="valueB"/>
> </logic:messagesPresent>
> . . . render the prompt for currentField, placing <c:out
> value="${foo}"/> where necessary (this could be a css class or font
> color, etc.) , , ,
>
> I am doing this for each field. Please let me know if there is a better
way.
>
> Thanks,
> Erik
>
>
>
> Erik Weber wrote:
>
> > I see that the ActionErrors object is stored as a request attribute
> > under the key "org.apache.struts.action.ERROR".
> >
> > I would like to set a different CSS class for each <td> containing a
> > field that has a property that is keyed in the ActionErrors instance.
> > In pseudocode:
> >
> > begin "username" field;
> > if (ActionErrors instance exists and ActionErrors instance contains
> > any ActionErrors for the "username" property) {
> > open td with class set to "style B";
> > print prompt for username field;
> > print username field;
> > close td;
> > }
> > else {
> > open td with class set to "style A";
> > print prompt for username field;
> > print username field;
> > close td;
> > }
> >
> > . . . and so on, for each field. This seemingly could get to be a lot
> > of code. Any Struts/JSTL tag tricks I can use?
> >
> >
> > Thanks,
> > Erik
> >
> >
> >
> >
> > Erik Weber wrote:
> >
> >> In a JSP containing a form, what is the easiest way to see if a form
> >> validation error message exists for a particular, say, html:text
> >> field, when that page is processing after form validation has failed?
> >> For example, what if you wanted to present the messages field by
> >> field instead of all together at the top of the page? I assume the
> >> error messages are keyed according to the value of the "property"
> >> attribute for each field, or something similar?
> >>
> >> Thanks,
> >> Erik
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>



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


Re: Retrieving specific form validation error messages

Posted by Erik Weber <er...@mindspring.com>.
This is what I came up with:

<c:set var="foo" value="valueA"/>
<logic:messagesPresent name="org.apache.struts.action.ERROR" 
property="currentField">
<c:set var="foo" value="valueB"/>
</logic:messagesPresent>
. . . render the prompt for currentField, placing <c:out 
value="${foo}"/> where necessary (this could be a css class or font 
color, etc.) , , ,

I am doing this for each field. Please let me know if there is a better way.

Thanks,
Erik



Erik Weber wrote:

> I see that the ActionErrors object is stored as a request attribute 
> under the key "org.apache.struts.action.ERROR".
>
> I would like to set a different CSS class for each <td> containing a 
> field that has a property that is keyed in the ActionErrors instance. 
> In pseudocode:
>
> begin "username" field;
> if (ActionErrors instance exists and ActionErrors instance contains 
> any ActionErrors for the "username" property) {
> open td with class set to "style B";
> print prompt for username field;
> print username field;
> close td;
> }
> else {
> open td with class set to "style A";
> print prompt for username field;
> print username field;
> close td;
> }
>
> . . . and so on, for each field. This seemingly could get to be a lot 
> of code. Any Struts/JSTL tag tricks I can use?
>
>
> Thanks,
> Erik
>
>
>
>
> Erik Weber wrote:
>
>> In a JSP containing a form, what is the easiest way to see if a form 
>> validation error message exists for a particular, say, html:text 
>> field, when that page is processing after form validation has failed? 
>> For example, what if you wanted to present the messages field by 
>> field instead of all together at the top of the page? I assume the 
>> error messages are keyed according to the value of the "property" 
>> attribute for each field, or something similar?
>>
>> Thanks,
>> Erik
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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


Re: Retrieving specific form validation error messages

Posted by Erik Weber <er...@mindspring.com>.
I see that the ActionErrors object is stored as a request attribute 
under the key "org.apache.struts.action.ERROR".

I would like to set a different CSS class for each <td> containing a 
field that has a property that is keyed in the ActionErrors instance. In 
pseudocode:

begin "username" field;
if (ActionErrors instance exists and ActionErrors instance contains any 
ActionErrors for the "username" property) {
open td with class set to "style B";
print prompt for username field;
print username field;
close td;
}
else {
open td with class set to "style A";
print prompt for username field;
print username field;
close td;
}

. . . and so on, for each field. This seemingly could get to be a lot of 
code. Any Struts/JSTL tag tricks I can use?


Thanks,
Erik




Erik Weber wrote:

> In a JSP containing a form, what is the easiest way to see if a form 
> validation error message exists for a particular, say, html:text 
> field, when that page is processing after form validation has failed? 
> For example, what if you wanted to present the messages field by field 
> instead of all together at the top of the page? I assume the error 
> messages are keyed according to the value of the "property" attribute 
> for each field, or something similar?
>
> Thanks,
> Erik
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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