You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Nathan Quirynen <na...@pensionarchitects.be> on 2013/07/08 10:56:20 UTC
Conditional translator
Hi,
In multiple forms I have a textfield containing a bank account number
and next to it a select component containing the account number type (enum).
Now I want to add a translator for the textfield, to automaticaly format
the value, but the formatting is different for each account number type.
I now have a translator for each type, but it would be nice if i could
make just 1 and somehow pass the type. Is there a way to do this?
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Conditional translator
Posted by Ivan Khalopik <ik...@gmail.com>.
You can dynamically create translator:
@Inject
private FieldTranslatorSource fieldTranslatorSource;
public getMyTranslator() {
switch(myAccountType) {
case ACCOUNT_TYPE1:
return createTranslator("myField", "myTranslator1");
// other types
}
return null;
}
protected FieldTranslator createTranslator(final String componentId, final
String translator) {
final ComponentResources componentResources =
resources.getEmbeddedComponent(componentId).getComponentResources();
return fieldTranslatorSource.createTranslator(componentResources,
translator);
}
In this example account type should be populated before account number. So
if select is placed after textfield it will result with incorect behaviour.
To fix this I usually use trick with FormFragment component:
<t:formfragment visible="true">
<t:textfield .../>
</t:formfragment/>
<t:select .../>
On Mon, Jul 8, 2013 at 11:56 AM, Nathan Quirynen <
nathan@pensionarchitects.be> wrote:
> Hi,
>
> In multiple forms I have a textfield containing a bank account number and
> next to it a select component containing the account number type (enum).
> Now I want to add a translator for the textfield, to automaticaly format
> the value, but the formatting is different for each account number type. I
> now have a translator for each type, but it would be nice if i could make
> just 1 and somehow pass the type. Is there a way to do this?
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<us...@tapestry.apache.org>
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
BR
Ivan