Issue Details (XML | Word | Printable)

Key: STR-1305
Type: New Feature New Feature
Status: In Progress In Progress
Priority: Major Major
Assignee: Paul Benedict
Reporter: Leonardo Quijano
Votes: 1
Watchers: 1
Operations

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

Add <html:label> tag to output HTML label

Created: 15/Mar/03 04:56 AM   Updated: 12/Oct/07 03:13 AM
Return to search
Component/s: Tag Libraries
Affects Version/s: None
Fix Version/s: 1.4.0

Environment:
Operating System: All
Platform: All
Issue Links:
Dependency
 

Bugzilla Id: 18015


 Description  « Hide
It would be useful to have a tag that just writes a form's value.
We already have one:

<html:hidden property="foo" write="true" />

The problem is that it generates a HTML INPUT in addittion to the text. That
INPUT could interfere with the form's submission, and it adds bloat to the
page.It would be nice to have a custom tag just to generate the form's text.

I know i could also expose the form as a bean (I guess it would be <bean:struts
... />). But that could tie the JSP to the form's name, and that's not a good think.

Maybe the tag could be something like:

<html:label property="foo" />

And it would get property "foo" from the form and write it like a bean:write. It
could be even:

<html:label property="foo.x.y.z" />

Leonardo

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Ted Husted added a comment - 17/Mar/03 01:22 AM
I can see the case for a html:write tag -- a bean:write that defaulted to the
bean for the enclosing form tag. I'll make this LATER in case anyone wants to
followup with an implementation.


Matt Raible added a comment - 13/May/03 09:06 PM
I got the idea and original source from Erik Hatcher - but this is a pretty
slick (IMO) label tag that also contains enhancements for the Validator to
indicate required fields and errors.

http://tinyurl.com/bndn

David Graham added a comment - 25/Jun/03 09:41 AM
The idea is good but there are a couple of things about the implementation that
bother me. Forcing people to use specific message resources keys is not a good
idea because they may have used that key for something else. The "key"
attribute should be a free form key into the resources that grabs the label
text. Then a "property" attribute would define what form field the label
applies to (property may not be the best term but it matches the current Struts
convention).

It's not intuitive that styleClass means required. The styleClass attribute
should be renamed requiredStyleClass and errorClass should be renamed
errorStyleClass to match the Struts convention. The styles have hardcoded
defaults in the tag ("required" for requiredStyleClass and "error" for
errorStyleClass) that need to be removed (the user might have defined an "error"
style that they're quite fond of but don't want to use with LabelTag). If the
user doesn't specify a class in the tag's attribute it shouldn't use one.

Alternatively, I've found that a good way of allowing an application wide
default (to relieve the burden of specifying the style each time) without
hardcoding it in the tag is to allow the user to specify an application context
parameter defined in web.xml. If not specified in the tag's attribute, the
value is looked up in the context parameter. If not found there, no style is
rendered. The parameter name to lookup in the context would be org.apache.
struts.taglib.html.LabelTag.requiredStyleClass.

Tag's should not presume to know what user's defaults should be. I would
certainly use this tag if were included with Struts with the above
modifications.

David Graham added a comment - 25/Jun/03 08:40 PM
There is another proposal on this idea in STR-1525 .

Aldo Gutiérrez added a comment - 23/Sep/04 02:39 AM
I think we don't need a <html:label> tag

for write a forms (ActionForm) value i simply used the <c:out> tag from de the
JSTL core tags library (I tested this with JDeveloper 10g Struts + JSTL)

Example for a DynaActionForm :

<c:out value="${revertion_consult.map.year}" />

for a ActionForm (no Dyna)

<c:out value="${revertion_consult.year}" />

You don't need to specify the scope where the bean (ActionForm) is

I supose you can do the same with the <bean:write> tag (i never used it)

However it will be very useful if DynaActionForm implements the
java.util.Map interface because in that way you can use
<c:out value="${revertion_consult.year}" /> for both ActionForm
and DynaActionForm

I don't see any problem to tie the JSP to the form's name.

Sorry for my ugly English

Leonardo Quijano added a comment - 23/Sep/04 02:55 AM
This <html:label> is for people using J2EE 1.2. There's no support for JSTL
there ;).

Stewart Cambridge added a comment - 19/Oct/05 04:39 AM
(In reply to comment #0)
I came to this page by googling for <html:label because I wanted (and thought it
might be implemented) a taglib tag for rendering the normal HTML tag <label
for="control's id">Some text</label> but where I could set for="" using EL.
IE, HTML has this ability:
<label for="checkbox1">Check Me!</label>
<input type="checkbox" value="yes" id="checkbox1"/>

And I wanted to do:
<label for="${dynamic_id}">Check Me!</label>
<input type="checkbox" value="yes" id="${dynamic_id}"/>

However, the functionality you are discussing has nothing to do with the HTML
<label> tag.
I can see this discussion is old, and I'm not on Strust 1.2.7 where
errorStyle="" is now implemented, so maybe my point is pointless, but:
Don't use <html:label> for anything other than rendering the normal <label> !!

Is it obvious why?

Stewart Cambridge
stewart.cambridge@gmail.com



> It would be useful to have a tag that just writes a form's value.
> We already have one:
>
> <html:hidden property="foo" write="true" />
...
> Maybe the tag could be something like:
>
> <html:label property="foo" />
...
> Leonardo

Paul Benedict added a comment - 05/Sep/06 01:23 AM
I have been in need of this feature. For my situation, not only do I want error messages and the erred fields highlighted, but also to change the style of my field labels.

Paul Benedict added a comment - 05/Sep/06 01:32 AM
I agree with Stewart: the proposed <html:label> should output an HTML <label>, and allow leveraging of the custom error attributes that's part of the Struts tag library. That's my proposed implementation.

Ralf Hauser added a comment - 08/Oct/07 07:55 PM
a work-around already available with current tags (in particular if the "required" validator fails and thus the field is empty) is to use a 50% transparent backgound image.
This way, even if you have a input-"cell"-background color as "focus" style, you still can see if an empty fields is in error

see also: http://www.niallp.pwp.blueyonder.co.uk/strutshighlight.html and http://mail-archives.apache.org/mod_mbox/struts-dev/200306.mbox/%3C20030625134317.21964.qmail@web20711.mail.yahoo.com%3E

Furthermore, in presence of errors, the focus better is with an erroneous fields ==> see STR-3104

Paul Benedict added a comment - 12/Oct/07 03:13 AM
I have a class to commit when I get free time. It's close to Matt Raible's implementation.