You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Adam Lister <al...@MIT.EDU> on 2008/11/12 17:39:44 UTC

Highlighting a field with a validation error in struts 2

Hi,

I'm trying to figure out how apply a class or some kind of style to a 
input field when there is a validation error in struts 2.  I think this 
is a fairly common thing (apply a highlighted background color to an 
errored field to focus the user's attention) but it does not seem to be 
supported with the canned struts2 themes.  Am I missing something, or 
would I have to override the themes myself to achieve this kind of 
functionality?  Is there some other way I am missing? Thanks.

-Adam Lister

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


Re: Highlighting a field with a validation error in struts 2

Posted by Torsten Krah <tk...@fachschaft.imn.htwk-leipzig.de>.
Am Mittwoch, 12. November 2008 schrieb Adam Lister:
> I'm not seeing this "red border" either...
> does anyone recall which theme provides this?

Afaik no theme does provide this, you have to write your own theme (actual for 
this input field only) to do this - its really easy to do that.



Re: Highlighting a field with a validation error in struts 2

Posted by Arpan Debroy <ar...@gmail.com>.
If we use "simple" theme, then also can we make that?

On Thu, Nov 13, 2008 at 12:18 PM, Andras Balogh <an...@reea.net> wrote:

> Hi,
>
> I think the easiest way would be to copy from struts2-core-xx.jar the
> validation.js based on the theme and put it in your source package folder .
> So example I took template/css_xhtml/validation.js from struts.jar and I
> modified the javascript function:
> function addError(e, errorText)
> {
> }
> Here the 'e' is the form element so you can easily style it with
> javascript.
> This applies to the Struts 2.0.11.2, I don't know about newer versions but
> I think you can do the same.
>
> See here about Overriding Templates:
> http://struts.apache.org/2.0.12/docs/template-loading.html
>
> Best regards,
> Andras.
>
>
> Adam Lister wrote:
>
>> I took a look around, and I can't seem to find any way to select an input
>> that has an error associated with it using css.  The samples I've looked at
>> have ways to style the error message text, the label, etc, but no way to
>> style an input.  I'm not seeing this "red border" either... does anyone
>> recall which theme provides this?
>>
>> Thanks,
>> -Adam
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Thanks & Regards
 Arpan Debroy

AOL Online India Private Ltd
RMZ EcoSpace Campus 1A
Outer Ring Road, Bellandur,
Bangalore - 560037
India
Mobile No :+9886006306
on-board :+91 (80) 4035 4528
E-mail : arpan.debroy@corp.aol.com

Re: Highlighting a field with a validation error in struts 2

Posted by Andras Balogh <an...@reea.net>.
Hi,

I think the easiest way would be to copy from struts2-core-xx.jar the 
validation.js based on the theme and put it in your source package folder .
So example I took template/css_xhtml/validation.js from struts.jar and I 
modified the javascript function:
function addError(e, errorText)
{
}
Here the 'e' is the form element so you can easily style it with javascript.
This applies to the Struts 2.0.11.2, I don't know about newer versions 
but I think you can do the same.

See here about Overriding Templates:
http://struts.apache.org/2.0.12/docs/template-loading.html

Best regards,
Andras.


Adam Lister wrote:
> I took a look around, and I can't seem to find any way to select an 
> input that has an error associated with it using css.  The samples 
> I've looked at have ways to style the error message text, the label, 
> etc, but no way to style an input.  I'm not seeing this "red border" 
> either... does anyone recall which theme provides this?
>
> Thanks,
> -Adam


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


Re: Highlighting a field with a validation error in struts 2

Posted by Dave Newton <ne...@yahoo.com>.
Sorry if this is a dupe; something funky is happening.

--- On Wed, 11/12/08, Adam Lister wrote:
> I took a look around, and I can't seem to find any way
> to select an input that has an error associated with it using css.

You should be able to use CSS selectors to get child elements of an element of a given style. That said, it'd be easier to modify the templates to provide whatever IDs you need. See below.

> The samples I've looked at have ways to style the error message text, 
> the label, etc, but no way to style an input.  I'm not seeing this
> "red border" either... does anyone recall which theme provides this?

Oh, I guess I did that; sorry. Been so long I thought it was part of the framework :) I guess I modified the templates to add some IDs; I have a patch that I haven't applied yet because I keep forgetting.

Dave


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


Re: Highlighting a field with a validation error in struts 2

Posted by Adam Lister <al...@MIT.EDU>.
I took a look around, and I can't seem to find any way to select an 
input that has an error associated with it using css.  The samples I've 
looked at have ways to style the error message text, the label, etc, but 
no way to style an input.  I'm not seeing this "red border" either... 
does anyone recall which theme provides this?

Thanks,
-Adam

Dave Newton wrote:
> --- On Wed, 11/12/08, Adam Lister <al...@MIT.EDU> wrote:
>   
>> I'm trying to figure out how apply a class or some kind
>> of style to a input field when there is a validation error
>> in struts 2.
>>     
>
> I generally just override the supplied CSS (which does things like giving text boxes with errors a red border already, IIRC). Highlighting the entire row currently involves more CSS selectorship than necessary, and I haven't gotten around to applying my patch that provides more DOM names and ids yet.
>
> Dave
>
>
> ---------------------------------------------------------------------
> 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: Highlighting a field with a validation error in struts 2

Posted by Dave Newton <ne...@yahoo.com>.
--- On Wed, 11/12/08, Adam Lister <al...@MIT.EDU> wrote:
> I'm trying to figure out how apply a class or some kind
> of style to a input field when there is a validation error
> in struts 2.

I generally just override the supplied CSS (which does things like giving text boxes with errors a red border already, IIRC). Highlighting the entire row currently involves more CSS selectorship than necessary, and I haven't gotten around to applying my patch that provides more DOM names and ids yet.

Dave


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