Issue Details (XML | Word | Printable)

Key: STR-1525
Type: Improvement Improvement
Status: Open Open
Priority: Minor Minor
Assignee: Unassigned
Reporter: Jonathan R. DeRose
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Struts 1

Enhanced Error Handling & Style Control

Created: 15/Jun/03 01:44 PM   Updated: 20/Aug/07 09:58 AM
Return to search
Component/s: Tag Libraries
Affects Version/s: Nightly Build
Fix Version/s: Future

File Attachments:
  Size
Java Source File LabelTag.java 2003-06-27 11:11 PM Jonathan R. DeRose 3 kB
Java Source File LabelTag.java 2003-06-26 04:04 AM Jonathan R. DeRose 2 kB
Java Source File LabelTag.java 2003-06-15 01:49 PM Jonathan R. DeRose 1 kB
Text File style_control_complete_report.txt 2003-06-15 01:48 PM Jonathan R. DeRose 76 kB
Text File updated_error_handling_diff_report.txt 2003-06-26 04:12 AM Jonathan R. DeRose 76 kB
Environment:
Operating System: All
Platform: All

Bugzilla Id: 20784


 Description  « Hide
This enhancement allows users to set up default styles (style, styleClass,
styleId, errorStyle, errorStyleClass, errorStyleId) in a resource bundle (Ex:
ApplicationResources.properties).

When an input element is rendered a check is made to see if any errors are
associated with it. If errors are associated the tag will use any error-styles
assigned to it, otherwise it will use the non-error-styles. (Ex: A developer
can set an errorStyleClass that will highlight text inputs with errors in red.)

A new tag (LabelTag) is also included in this enhancement. LabelTags are
associated with input elements. It will apply different styles to its body
content in the same fashion as the input elements. (Ex: A normal black label
can turn red and bold if its input fails validation.)


Basic behavior for this enhancment:
* Styles/error-styles assigned in-line override their counterparts in the
resource bundle.
* Non error-styles will be used regardless of errors if error-styles are not
assigned. (Ex: If you set the styleClass and not the errorStyleClass it will
use the styleClass regardless of errors.)
* Error-styles will only be used if errors are associated with the element.
(Ex: If you set the errorStyleClass and not the styleClass it will only use the
errorStyleClass when errors are associated.)
* Errors can be associated with specific input elements, groups of elements, or
both.


EXAMPLE:
====== ApplicationResources.properties =====
...
label.errorStyleClass=bold
...
text.styleClass=normal
text.errorStyleClass=red_error
...
===== test.jsp =====
...
<html:label group="name">Name:</html:label>
<html:text property="firstName" group="name"/>
<html:text property="lastName" group="name"/>
...
<html:label group="ssn">SSN:</html:label>
<html:text property="ssn1" group="ssn" errorStyleClass="blue_error"/>
<html:text property="ssn2" group="ssn" errorStyleClass="blue_error"/>
<html:text property="ssn3" group="ssn" errorStyleClass="blue_error"/>
...
===== output with no errors =====
...
Name:
<input type="text" name="firstName" class="normal">
<input type="text" name="lastName" class="normal">
...
SSN:
<input type="text" name="ssn1" class="normal">
<input type="text" name="ssn2" class="normal">
<input type="text" name="ssn3" class="normal">
...
===== output with error on name and ssn ===
...
<span class="bold">Name:</span>
<input type="text" name="firstName" class="red_error">
<input type="text" name="lastName" class="red_error">
...
<span class="bold">SSN:</span>
<input type="text" name="ssn1" class="blue_error">
<input type="text" name="ssn2" class="blue_error">
<input type="text" name="ssn3" class="blue_error">
...
===== output with error on lastName =====
...
Name:
<input type="text" name="firstName" class="normal">
<input type="text" name="lastName" class="red_error">
...
SSN:
<input type="text" name="ssn1" class="normal">
<input type="text" name="ssn2" class="normal">
<input type="text" name="ssn3" class="normal">
...



This ticket is an enhancement of a previous ticket and replaces STR-1510
http://issues.apache.org/bugzilla/show_bug.cgi?id=20630

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Jonathan R. DeRose added a comment - 15/Jun/03 01:48 PM
Created an attachment (id=6837)
Complete Diff Report (all changes except the new LabelTag)

Jonathan R. DeRose added a comment - 15/Jun/03 01:49 PM
Created an attachment (id=6838)
LabelTag.java - Source Code for new Tag

Jonathan R. DeRose added a comment - 15/Jun/03 02:05 PM
*** STR-1510 has been marked as a duplicate of this bug. ***

David Graham added a comment - 25/Jun/03 08:41 PM
There is another proposal on this topic in STR-1305.

Jonathan R. DeRose added a comment - 26/Jun/03 04:04 AM
Created an attachment (id=6978)
Updated LabelTag that uses resource bundles or body content for the label

Jonathan R. DeRose added a comment - 26/Jun/03 04:12 AM
Created an attachment (id=6979)
Updated diff report (-u format)

Jonathan R. DeRose added a comment - 26/Jun/03 04:28 AM
I have modified the LabelTag (thanks to some great ideas from listserv) to use
a label from the resource properties if a key is provided. If a key is not
provided, the body content of the label tag will be used as previously
described.

Now you will get error handling for either of the following:
<html:label property="password" key="label.property"/>
-or-
<html:label property="password">Password</html:label>

The two attachements marked *updated* contain the current code.

HTH,
Jonathan R. DeRose

PS. Doah! while writing this I realized I left out the release method for the
updated LabelTag (reseting the key to null), I will add it tomorrow. Sorry
about that.

Jonathan R. DeRose added a comment - 27/Jun/03 11:11 PM
Created an attachment (id=7020)
Updated LabelTag can now be easily extended (to add formatting for required fields or other mods)

Stefan Kuehnel added a comment - 28/Jun/03 05:11 PM
This tag sounds like a very good addition to Struts. The only thing I was
wondering is, why you're using <span> markup for the label text and not <label>
(http://www.w3.org/TR/html4/interact/forms.html#h-17.9):




   <form action="foo.do">


      <p>


      <label class="error" for="firstNameId">First name:</label>


      <input id="firstNameId" name="firstName" type="text">


      <br>


      <label style="normal" for="lastNameId">Last name:</label>


      <input id="lastNameId" name="lastName" type="text" value="">


      </p>


   </form>




The only reason I could see is that <label> is a HTML4 addition, but all modern
browsers (IE6, Opera7, Netscape7 are the ones I checked) support it. So having
the option to use <label> would be great.



David Graham added a comment - 29/Jun/03 12:41 AM
It should use <label> when added to Struts.

Jonathan R. DeRose added a comment - 03/Jul/03 10:42 PM
I agree, I had originally used <SPAN> tags cause <LABEL> does not support
the 'class' and 'style' attributes for Netscape 4.* but I did some research and
it looks like IE (5.0, 5.5, & 6.0) has a combined 95% of the market.
(http://www.onestat.com/html/aboutus_pressbox15.html)

I have made the changes to the LabelTag, but with the release of 1.1 and the
flurry of changes to the HTML tag library I will have to wait a bit so I can
make a new patch against the latest files. (The real reason for delay is I am
leaving today for a two week trip to Germany and I have been running around
getting ready for that.)

Jonathan

Niall Pemberton added a comment - 04/Oct/04 01:02 AM
I have implemented a slightly modified version of your patch to add "error
styles" to the html tags.

There are now 'errorStyle', 'errorStyleClass', 'errorStyleId' and 'errorKey'
attributes for the following tags: CheckboxTag, FileTag, MultiboxTag,
PasswordTag, RadioTag, SelectTag, TextTag and TextareaTag.

The 'errorStyle', 'errorStyleClass' and 'errorStyleId' attributes are
equivalents of the 'style', 'styleClass' and 'styleId' attributes for errors
(as you had them in your patch).

The 'errorKey' attribute is the name of the request scope bean under which the
error messages have been stored, with the default being Globals.ERROR_KEY if
not specified - works the same as the 'name' attribute on the ErrorsTag.

Should be available in the next nightly build (date 4th October 2004) if you
want to test them out, available here:

http://cvs.apache.org/builds/jakarta-struts/nightly/

Niall

Joe Germuska added a comment - 13/Apr/05 06:25 AM
Just today I was wondering about using the label tag, and I'm wondering what the
current status of this ticket is. It seems as though some parts of this were
already implemented, but what about html:label itself? Was there a reason not
to do it, or is it just that no one has gotten to it?

Is there any reason not to mark STR-1305 a duplicate of this one and leave this
as the nexus for discussion of support for the HTML 4 <LABEL> tag?

Paul Benedict added a comment - 05/Sep/06 01:29 AM
If the proposed <html:label> field does not output a label, I say this does not exactly fit into the HTML tag library family. Also the problem with this ticket is that it is trying to solve two different problems: (1) default error styles in a properties file and then (2) create a new label tag.

STR-1305 specifically deals with the use of <html:label> outputting the HTML label.

STR-1525 (this ticket) should only deal with a default error style.

Unless somebody objects, I will develop the <html:label> under STR-1305 leaving this for the default error style enhancement.