On 5/25/2011 2:08 PM, Josh Canfield wrote:
Previously I used a component
with parameters, but that interfered with validation
I'd go with a component. Your trouble with validation was possibly
that you were trying to validate based on the id of the textfield from
within your AxFormField component instead of the id of the AxFormField
component? Validation is an event which bubbles up through it's
containers. Using a component is the right approach when you want/have
to use a template.
Well, I had two problems. Although you inspired me to look at them
again, and fix both, so thank you.
The first problem was that all the textfields were called
"textfield_###", which made writing page tests pretty annoying; the
second problem was that while @Validate() worked fine, .properties files
with custom messages wouldn't work unless I used the textfield_### ID.
(so really one problem with two side effects, I think)
Eventually I fixed this by having an AxTextField like so:
public class AxTextField implements Field {
@Inject
private ComponentResources componentResources;
@Inject
private JavaScriptSupport jsSupport;
@Component(publishParameters =
"label,annotationProvider,clientId,disabled,nulls,translate,value,id,validate")
@Property
private TextField textfield;
private String clientId;
public void setupRender() {
clientId = jsSupport.allocateClientId(componentResources);
}
@Override
public String getControlName() {
return textfield.getControlName();
}
@Override
public boolean isDisabled() {
return textfield.isDisabled();
}
@Override
public boolean isRequired() {
return textfield.isRequired();
}
@Override
public String getClientId() {
return clientId;
}
@Override
public String getLabel() {
return textfield.getLabel();
}
}
And the associated template:
<?xml version="1.0" encoding="utf-8" ?>
<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
<t:AxFormField>
<t:label t:for="textfield" />
<div class="ax_input">
<t:error
class='literal:errorMsg'
for="textfield"
/>
<t:textfield
t:id="textfield"
class='input txtinput'
t:clientId="${clientId}"
/>
</div>
</t:AxFormField>
</t:container>
And this works great. Validation is all-go and I can use .properties
files for clean localization. I've also tested the disabled="" parameter
and it works.
So all's well!
Thanks again.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org