You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Jeff Robertson <Je...@magnetbanking.com> on 2003/06/09 14:29:55 UTC

RE: Introduction and a proprosal to add new functionality to Stru ts: Automatic highlighting of errored form elements

> -----Original Message-----
> 
> A quick note, when I wrote 'automatic highlighting of errored form
> elements': it is only automatic if a style has been defined to use.
> Example:
> < html:text property="name" styleClass="valid" 
> errorStyleClass="invalid" ...
> where 'valid' is the css style class to use normally and 
> 'invalid' would be
> used if there was an error.
> if no errorStyleClass was defined, there would be no highlighting.
> 

Do you also have an alternate style for the input's label text?

For instance, a form often looks like this:

<bean:message key="firstName"/> <html:text property="firstName" /><br>
<bean:message key="lastName"/> <html:text property="lastName" /><br>
<bean:message key="address"/> <html:text property="address" /><br>

If the "address" property fails validation, then one would normally expect
that the bean message (which probably just displays the word "Enter you
Address Here" or something) would be highlighted as well.


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


Re: Introduction and a proprosal to add new functionality to Stru ts: Automatic highlighting of errored form elements

Posted by Graham Leggett <mi...@sharp.fm>.
Jeff Robertson wrote:

> Do you also have an alternate style for the input's label text?
> 
> For instance, a form often looks like this:
> 
> <bean:message key="firstName"/> <html:text property="firstName" /><br>
> <bean:message key="lastName"/> <html:text property="lastName" /><br>
> <bean:message key="address"/> <html:text property="address" /><br>
> 
> If the "address" property fails validation, then one would normally expect
> that the bean message (which probably just displays the word "Enter you
> Address Here" or something) would be highlighted as well.

Something else that's useful is to highlight something that might have 
changed, or a field that is new, in an environment that contains workflow.

Pablo Casado and myself came up with some code that compared beans using 
reflection to compare the values of the getters in the bean. If 
bean.getFoo() was different to bean2.getFoo(), then a String "foo" was 
added to a List.

If the string "foo" existed in the List, then the style on that element 
was rendered as "changed" (in our case blue text instead of black text).

If anyone wants to look at the code, just shout.

Regards,
Graham
-- 
-----------------------------------------
minfrin@sharp.fm		"There's a moon
					over Bourbon Street
						tonight..."


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


RE: Introduction and a proprosal to add new functionality to Struts: Automatic highlighting of errored form elements

Posted by DeRose Jonathan <de...@bah.com>.
I took my enhancement a step farther today and set it up to work with the
ResourceBundle.  With this new implementation it is possible to set the
default styles you want to use once for the entire application.  With this
new implementation, you can set the styles to use in one place.  Before, you
would have to either 1)extend the tag library or 2)put the style attributes
in each and every tag.

I set it up so you can set default values to use for the following tags:
checkbox, label(new), multibox, password, radio, select, text, & textarea

The default values you can set are:
style, styleClass, styleId, errorStyle, errorStyleClass, errorStyleId

Example:
===== ApplicationResources.properties =====
errors.header=Errors Start:<ul>
...
...
LabelTag.errorStyleClass=invalid_label
LabelTag.styleClass=valid_label
...
TextTag.errorStyleClass=invalid
TextTag.styleClass=valid
...
...
===== test.jsp =====
<html:label property="name">Name:</html:label><html:text property="name"
size="10" />

===== output (if there IS an error on the name) =====
<SPAN class="invalid_label">Name:</SPAN><INPUT type="text" name="name"
class="invalid" size="10">

===== output (if there IS NOT an error on the name) =====
<SPAN class="valid_label">Name:</SPAN><INPUT type="text" name="name"
class="valid" size="10">

If you set your own style attributes they would override the defaults set in
the resource bundle:
<html:label property="name" styleClass="myStyleClass"
errorStyleClass="myErrorStyleClass">Name:</html:label>
<html:text  property="name" styleClass="myStyleClass"
errorStyleClass="myErrorStyleClass" size="10" />

I have the code working, but I wasn't sure if I was suppose to update the
current enhancement ticket or close it and create a new one...
-Jonathan



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


RE: Introduction and a proprosal to add new functionality to Struts: Automatic highlighting of errored form elements

Posted by DeRose Jonathan <de...@bah.com>.
Yes, that is part of the modifications I am proprosing.
The way I have set it up to work currently involves the creation of a new
LabelTag that would be used the following way.

<html:label property="firstName" styleClass="normal"
errorStyleClass="error"><bean:message key="firstName"/></html:label>

(if the users extended the LabelTag and set up default values)
public class LabelTag extends the.struts.LabelTag {
    public LabelTag() {
        super();
        super.setStyleClass(Constants.NORMAL);
        super.setErrorStyleClass(Constants.ERROR);
        ...
}

Then it would be dumbed down to: (where input is the extended tag library)
<input:label property="firstName"><bean:message
key="firstName"/></input:label>

I chose to keep presentation out of the bean library for two reasons:
* MessageTag currently does not specify any type of style, and I thought it
would be cleaner to keep it that way.
* By wrapping whatever they want with the new LabelTag, developers are not
locked in to using the MessageTag to get formatted messages.

-Jonathan




-----Original Message-----
From: Jeff Robertson [mailto:Jeff.Robertson@magnetbanking.com]
Sent: Monday, June 09, 2003 8:30 AM
To: 'Struts Developers List'
Subject: RE: Introduction and a proprosal to add new functionality to
Struts: Automatic highlighting of errored form elements


> -----Original Message-----
>
> A quick note, when I wrote 'automatic highlighting of errored form
> elements': it is only automatic if a style has been defined to use.
> Example:
> < html:text property="name" styleClass="valid"
> errorStyleClass="invalid" ...
> where 'valid' is the css style class to use normally and
> 'invalid' would be
> used if there was an error.
> if no errorStyleClass was defined, there would be no highlighting.
>

Do you also have an alternate style for the input's label text?

For instance, a form often looks like this:

<bean:message key="firstName"/> <html:text property="firstName" /><br>
<bean:message key="lastName"/> <html:text property="lastName" /><br>
<bean:message key="address"/> <html:text property="address" /><br>

If the "address" property fails validation, then one would normally expect
that the bean message (which probably just displays the word "Enter you
Address Here" or something) would be highlighted as well.


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




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