I solved the problem.
Translators are registered like this
public static void contributeTranslatorSource(Configuration<Translator>
configuration,
NumericTranslatorSupport support) {
configuration.add(new PhoneTranslator());
}
and here a simple translator implementation
public class PhoneTranslator extends AbstractTranslator<Phone>{
public PhoneTranslator() {
super("phone", Phone.class, "phone");
}
public String toClient(Phone value) {
return String.format("%s,%s,%s", value.getCountryCode(),
value.getAreaPrefix(), value.getCode());
}
public Phone parseClient(Field field, String clientValue, String
message) throws ValidationException {
String[] strings = clientValue.split(",");
if(strings.length != 3)
throw new ValidationException(message);
return new Phone(strings[0], strings[1], strings[2]);
}
public void render(Field field, String message, MarkupWriter writer,
FormSupport formSupport) {
}
Sebastian Hennebrueder schrieb:
Hello,
I got stuck writing my own editor.
I have a Phone class with three String fields countryPrefix, prefix, code.
I would like to render a simple text input field and translate the input
to a Phone class object. But I get the following exception.
org.apache.tapestry5.internal.services.RenderQueueException
Render queue error in BeginRender[PhoneBlock:phone]: Parameter
'translate' of component PhoneBlock:phone is bound to null. This
parameter is not allowed to be null.
The line below ( FieldTranslator translator =
context.getTranslator(phone);) is returning null
Do you have any idea? I read carefully the following pages
http://tapestry.apache.org/tapestry5/guide/beaneditform.html
http://wiki.apache.org/tapestry/Tapestry5HowToCreateAPropertyEditBlock?highlight=%28propertyeditblock%29
http://wiki.apache.org/tapestry/Tapestry5LocalizedDateField (This one
worked)
Here is my code
In my AppModule I have
public static void
contributeDefaultDataTypeAnalyzer(MappedConfiguration<Class, String>
configuration) {
configuration.add(Phone.class, "phoneNumber");
}
public static void
contributeBeanBlockSource(Configuration<BeanBlockContribution>
configuration) {
configuration.add(new BeanBlockContribution("phoneNumber",
"PhoneBlock", "phone", true));
}
In my pages package I have the following page class in
java/mypackage/pages
public class PhoneBlock {
@Property
@Environmental
private PropertyEditContext context;
@Component(parameters =
{"value=context.propertyValue", "label=prop:context.label",
"translate=prop:phoneTranslator",
"validate=prop:phoneValidator",
"clientId=prop:context.propertyId",
"annotationProvider=context"})
private TextField phone;
public FieldValidator getPhoneValidator() {
FieldValidator fieldValidator = context.getValidator(phone);
return fieldValidator;
}
public FieldTranslator getPhoneTranslator() {
FieldTranslator translator = context.getTranslator(phone);
return translator;
}
}
The corresponding PhoneBook.tml in resources/mypackage/pages
<div xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
<t:block id="phone">
<t:label for="phone"/>
<t:textfield t:id="phone" size="10"/>
</t:block>
</div>
--
Best Regards / Viele Grüße
Sebastian Hennebrueder
-----
Software Developer and Trainer for Hibernate / Java Persistence
http://www.laliluna.de
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org