You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Bob Stine <bo...@waltonstine.net> on 2004/02/10 17:27:15 UTC
ANSWER: Tapestry bindings to force upper case
My problem was how to force-to-upper-case a bunch of TextField components that I have bound to OGNL expressions. If possible, I wanted to avoid writing separate (cluterring, repetitive) setter methods for each of these text fields.
H.M. Lewis Ship (he's the man!) answered:
You probably could make use of ValidField and create a validator (or validator subclass) that did the conversion.
Bingo!
I specified a "delegate" attribute for the Form component that has the numerous TextFields that need to be upper-cased:
<bean name="delegate" class="net.sf.tapestry.valid.ValidationDelegate"/>
<!-- I'm running Tapestry 2.3, hence the net.sf.tapestry.valid package -->
<component id="form" type="Form">
<binding name="listener" expression="listeners.formSubmit"/>
<binding name="delegate" expression="beans.delegate"/>
</component>
In the .jwc file that contained the fields that need to be upper-cased, added a bean defintion for a hand-rolled validator class (see below)
<bean name="upperValidator" class="my.tapestry.package.UpperCaseValidator">
<set-property name="required" expression="false"/>
</bean>
and then for each field that needed to be upper-cased, I replaced the "TextField" components a "ValidField" components, e.g.:
<component id="myField" type="ValidField">
<binding name="value" expression="foo.bar.myField"/>
<binding name="validator" expression="beans.upperValidator"/>
<static-binding name="displayName">My Field</static-binding>
</component>
Finally, for the "bean" class, I wrote a minimal java class that extends Tapestry's StringValidator class. The only code it contains is an over-ride of its parent's "toObject" method:
public Object toObject(IField iField, String input)
{
Object upperString = null;
if (input != null)
{
upperString = input.toUpperCase();
}
return upperString;
}
Voila! YMMV. As noted above, I'm running Tapestry 2.3.
Re: Better Answer? (Re: ANSWER: Tapestry bindings to force upper case)
Posted by Bill Lear <ra...@zopyra.com>.
On Tuesday, February 10, 2004 at 10:49:16 (-0800) Bob Stine writes:
>...
>Folks who, like me, need help with CSS, might want to look at the
>short CSS tutorial at:
>
>http://www.w3schools.com/css/
And, not to be missed is the stunning
http://www.csszengarden.com
Bill
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Better Answer? (Re: ANSWER: Tapestry bindings to force upper case)
Posted by Bob Stine <bo...@waltonstine.net>.
Bill Lear <ra...@zopyra.com> wrote: On Tuesday, February 10, 2004 at 08:27:15 (-0800) Bob Stine writes:
>My problem was how to force-to-upper-case a bunch of TextField
>components that I have bound to OGNL expressions. If possible, I
>wanted to avoid writing separate (cluterring, repetitive) setter
>methods for each of these text fields. ...
Could you not also control this with the stylesheet?
something {
text-transform: uppercase;
}
[longish alternate solution snipped]
Yup, that seems to work fine and is certainly more elegant.
I added the following entry to the style sheet:
.uppercase {text-transform: uppercase}
And then used the "class" attribute in the HTML template, e.g.:
<span jwcid="myComponent" columns="60" rows="3" class="uppercase"></span>
Folks who, like me, need help with CSS, might want to look at the short CSS tutorial at:
http://www.w3schools.com/css/
Re: ANSWER: Tapestry bindings to force upper case
Posted by Bill Lear <ra...@zopyra.com>.
On Tuesday, February 10, 2004 at 08:27:15 (-0800) Bob Stine writes:
>My problem was how to force-to-upper-case a bunch of TextField
>components that I have bound to OGNL expressions. If possible, I
>wanted to avoid writing separate (cluterring, repetitive) setter
>methods for each of these text fields. ...
Could you not also control this with the stylesheet?
something {
text-transform: uppercase;
}
[longish alternate solution snipped]
> ...
>Voila! YMMV. As noted above, I'm running Tapestry 2.3.
The CSS solution should work with 2.3.
Bill
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org