Hmmm, I'm guessing the answers to my questions below are "no, this isn't
possible." ;-)
Here's another question - is it possible in my custom Validator to get
the existing CSS classes on a component? For example, I currently have:
public void writeLabelAttributes(IMarkupWriter writer, IRequestCycle
cycle, IFormComponent component) {
if (isInError(component)) {
writer.attribute("class", "error");
}
}
public void writeAttributes(IMarkupWriter writer, IRequestCycle cycle,
IFormComponent component, IValidator
validator) {
if (isInError()) {
writer.attribute("class", "error");
}
}
But I'd prefer to have something like this:
public void writeLabelAttributes(IMarkupWriter writer, IRequestCycle
cycle, IFormComponent component) {
if (isInError(component)) {
writer.attribute("class", "error " +
component.getAttribute("class"));
}
}
public void writeAttributes(IMarkupWriter writer, IRequestCycle cycle,
IFormComponent component, IValidator
validator) {
if (isInError()) {
writer.attribute("class", "error " +
component.getAttribute("class"));
}
}
In other words, is there a method on component that allows me to get the
current CSS classes?
Matt
Matt Raible wrote:
I have two different "Label" components I'm trying to create.
Issue #1
---------------------------
The first is a simple component (just a Label.jwc and Label.html file
in WEB-INF) that writes a <label>. I'd like to include the option to
write a "required" indicator. However, I'm having a difficult time
retrieving a parameter's value. Here's what I have so far:
Label.jwc
<component-specification allow-informal-parameters="yes">
<parameter name="key" required="yes"/>
<parameter name="class" required="no"/>
<component id="label" type="Any" inherit-informal-parameters="yes"/>
</component-specification>
Label.html
<label jwcid="label"><span jwcid="@Insert"
value="ognl:getMessages().getMessage(key)"/> <div jwcid="@If"
condition="ognl:class == 'required'"><span class="req"> *</span></label>
I'm pretty sure "class" won't work as a parameter name b/c I've seen a
stacktrace using this already. Regardless, let's pretend it does
(I've tried using other names). Here's the desired usage:
<label class="required desc" jwcid="@Label" for="phoneNumber"
key="user.phoneNumber">Phone Number</label> produces:
<label class="desc" jwcid="@Label" for="phoneNumber">Phone Number<span
class="req"> *</label>
I'm fine with the result having class="required desc" - I basically
just need some indicator to show a field is required when I'm not
wiring up it's input field as a component.
Issue #2
---------------------------
I'm overriding ValidationDelegate in order to add required field
indicators. I used to be pre-pending an asterisk to the beginning of
the field, and I had that working. Now I want to add <span
class="req"> to the end of the <label> before the </label> shows up.
I'm using @FieldLabel and everything *almost* works. I've eliminating
error styling in the class below so it's easier to read.
public class Validator extends ValidationDelegate {
public void writeLabelSuffix(IFormComponent component,
IMarkupWriter writer, IRequestCycle
cycle) {
if (component.isRequired()) {
writer.begin("span");
writer.attribute("class", "req");
writer.printRaw(" *");
writer.end();
}
}
The code above results in <label>blah blah</label><span class="req">
*</span>, when I'd rather have the <span> w/in the <label>. I tried
overriding writeLabelAttributes(), but that doesn't seem to allow me
to create a new tag and write it out w/in the label. Am I missing
something here? Has anyone done something like this - or knows how to
add a <span> withing an @FieldLabel?
Thanks,
Matt
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]