|
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 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. There is another proposal on this idea in STR-1525 .
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 This <html:label> is for people using J2EE 1.2. There's no support for JSTL
there ;). (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 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.
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.
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 I have a class to commit when I get free time. It's close to Matt Raible's implementation.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bean for the enclosing form tag. I'll make this LATER in case anyone wants to
followup with an implementation.