You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Andreas Bulling <sp...@phoenix.hadiko.de> on 2006/03/04 12:09:01 UTC
Custom Validator/Translator
Hi everybody,
I followed the howto on the wiki to create a custom validator and
translator: A choice validator which only accepts two different
string values (like y/n) and a boolean translator which translates
this choice into corresponding boolean values. Both are configurable
by use of a parameter passed in the .page file.
The first problem was that (as described in the howto)
<binding name="translator" value="translator:gender,parameter"/>
didn't work - I got an java.lang.reflect.InvocationTargetException.
And yes, I have a constructor which accepts a String as parameter ;)
Using
<binding name="translator" value="translator:gender,parameter=value"/>
and providing a setter/getter in the translator works.
Is the first wrong? In this case I won't add my solution to
the wiki but replace the wrong one.
The second and even bigger problem is that I have a problem with
the combination of the validator/translator. What I want is
that first the validator checks if the choice was submitted
correctly and afterwards this choice is translated in a
corresponding boolean value (to be inserted in the database).
BUT:
As it seems the translator is called first, translates the
choice into a boolean and the validator fails afterwards :(
How can I accomplish this?
Thanks in advance!
Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Custom Validator/Translator
Posted by Massimo Lusetti <ml...@gmail.com>.
On 3/4/06, Andreas Bulling <sp...@phoenix.hadiko.de> wrote:
> How can I accomplish this?
I'm sorry but just want to add one more question to the list not an
answer, how could i use Validator to validate field content in
relation to the content of one another?
Let me explain, i wish field B having content greater then 10 if field
A is true while having it less then 10 otherwise.
Regards
--
Massimo
http://meridio.blogspot.com
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Custom Validator/Translator
Posted by Andreas Bulling <sp...@phoenix.hadiko.de>.
Hi,
thanks a lot for your helpful answer!
| You only need to implement one translator (which, if input is invalid can act
| like a validator).
That means that validators/translators are not designed to be used together
or perhaps just in some (standard) cases?
| The translator will have 2 properties, yesString + noString
| you'll define it in you .page like this:
| <bean name="ynTranslator"
| class="another.cool.Translator">
| <set name="yesString" value="message:yesChar" />
| <set name="noString" value="message:noChar" />
| </bean>
| and use it like this:
| <binding name="translator" value="bean:ynTranslator" />
|
| For each language you want to support, you just supply the localized
| versions of yesChar and noChar in the appropriate .properties file.
That looks great - I will try it ;)
Sincerly,
Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Custom Validator/Translator
Posted by an...@di.uoa.gr.
You only need to implement one translator (which, if input is invalid can act
like a validator).
The translator will have 2 properties, yesString + noString
you'll define it in you .page like this:
<bean name="ynTranslator"
class="another.cool.Translator">
<set name="yesString" value="message:yesChar" />
<set name="noString" value="message:noChar" />
</bean>
and use it like this:
<binding name="translator" value="bean:ynTranslator" />
For each language you want to support, you just supply the localized
versions of yesChar and noChar in the appropriate .properties file.
>From Andreas Bulling <sp...@phoenix.hadiko.de>:
> | I'm sorry. My bad. I guess I didn't read your post too carefully.
>
> No problem ;)
>
> | AFAIK translator by design runs first so that your validator can check
> | on the intended value.
>
> Well, in this case in my opinion this is bad design, isn't it?
> For example if I just want two different characters to be
> accepted by the validator (say y/n) and want to save their translated
> values (say 1/0) in the database afterwards wouldn't it be more
> intuitive to first check if the characters are valid and
> translate _afterwards_?
>
> At the moment, first I have to write a translator which translates
> them to boolean values and a validator which accepts (or rejects)
> them afterwards: That means _in the translator_ I have to make
> a hardcoded check for y and n (in this case) to be able to
> translate them to correct boolean values. But
> 1) then the validator isn't useful anymore because the "logic"
> is in the translator class
> 2) I have to do this for every language I want to support. Bad. :(
>
> Sincerly,
> Andreas
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
--
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Custom Validator/Translator
Posted by Andreas Bulling <sp...@phoenix.hadiko.de>.
| I'm sorry. My bad. I guess I didn't read your post too carefully.
No problem ;)
| AFAIK translator by design runs first so that your validator can check
| on the intended value.
Well, in this case in my opinion this is bad design, isn't it?
For example if I just want two different characters to be
accepted by the validator (say y/n) and want to save their translated
values (say 1/0) in the database afterwards wouldn't it be more
intuitive to first check if the characters are valid and
translate _afterwards_?
At the moment, first I have to write a translator which translates
them to boolean values and a validator which accepts (or rejects)
them afterwards: That means _in the translator_ I have to make
a hardcoded check for y and n (in this case) to be able to
translate them to correct boolean values. But
1) then the validator isn't useful anymore because the "logic"
is in the translator class
2) I have to do this for every language I want to support. Bad. :(
Sincerly,
Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Custom Validator/Translator
Posted by Adam Zimowski <zi...@gmail.com>.
I'm sorry. My bad. I guess I didn't read your post too carefully.
AFAIK translator by design runs first so that your validator can check
on the intended value. For instance, if you're collecting a String
which is a number translator will do its work and give you number so
that you can further check on it with the validator. If a translator
for some reason cannot translate because a value doesn't make sense,
then it will behave as if it were a validator.
So I'd validate on an already translated value, not the original.
On 3/6/06, Andreas Bulling <sp...@phoenix.hadiko.de> wrote:
> Hi Adam,
>
> thanks for your answer, but I don't understand how this is related
> to my problem?! I'm already using a custom ValidationDelegate
> and I've also set up both the translator and the validator
> in my hivemodule.xml file (I verified that they get called/used when
> submitting the form).
>
> My problem is the order of execution not that I don't know how
> to use a custom delegate/translator/validator ;)
>
> Sincerly and thanks again anyway,
> Andreas
>
> On 06. Mär 2006 - 10:28:28, Adam Zimowski wrote:
> | In your page class you can populate delegate object with your custom
> | validations. For instance, if you add the following to you page class:
> |
> | @Bean
> | public abstract ValidationDelegate getDelegate();
> |
> | you then can add errors to this delegate in your listener (onSubmit or
> | whatever). I suggest first to check javadoc on ValidationDelegate
> | object, play with it a little and you're gonna strik a home run :-)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Custom Validator/Translator
Posted by Andreas Bulling <sp...@phoenix.hadiko.de>.
Hi Adam,
thanks for your answer, but I don't understand how this is related
to my problem?! I'm already using a custom ValidationDelegate
and I've also set up both the translator and the validator
in my hivemodule.xml file (I verified that they get called/used when
submitting the form).
My problem is the order of execution not that I don't know how
to use a custom delegate/translator/validator ;)
Sincerly and thanks again anyway,
Andreas
On 06. Mär 2006 - 10:28:28, Adam Zimowski wrote:
| In your page class you can populate delegate object with your custom
| validations. For instance, if you add the following to you page class:
|
| @Bean
| public abstract ValidationDelegate getDelegate();
|
| you then can add errors to this delegate in your listener (onSubmit or
| whatever). I suggest first to check javadoc on ValidationDelegate
| object, play with it a little and you're gonna strik a home run :-)
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Custom Validator/Translator
Posted by Adam Zimowski <zi...@gmail.com>.
In your page class you can populate delegate object with your custom
validations. For instance, if you add the following to you page class:
@Bean
public abstract ValidationDelegate getDelegate();
you then can add errors to this delegate in your listener (onSubmit or
whatever). I suggest first to check javadoc on ValidationDelegate
object, play with it a little and you're gonna strik a home run :-)
On 3/6/06, Andreas Bulling <sp...@phoenix.hadiko.de> wrote:
> Is nobody out there who can help me with this problem?
> That would be very kind as I'm stuck completely with this issue... :(
>
> On 04. Mär 2006 - 12:09:01, Andreas Bulling wrote:
> | Hi everybody,
> |
> | I followed the howto on the wiki to create a custom validator and
> | translator: A choice validator which only accepts two different
> | string values (like y/n) and a boolean translator which translates
> | this choice into corresponding boolean values. Both are configurable
> | by use of a parameter passed in the .page file.
> |
> | The first problem was that (as described in the howto)
> |
> | <binding name="translator" value="translator:gender,parameter"/>
> |
> | didn't work - I got an java.lang.reflect.InvocationTargetException.
> | And yes, I have a constructor which accepts a String as parameter ;)
> |
> | Using
> |
> | <binding name="translator" value="translator:gender,parameter=value"/>
> |
> | and providing a setter/getter in the translator works.
> | Is the first wrong? In this case I won't add my solution to
> | the wiki but replace the wrong one.
> |
> | The second and even bigger problem is that I have a problem with
> | the combination of the validator/translator. What I want is
> | that first the validator checks if the choice was submitted
> | correctly and afterwards this choice is translated in a
> | corresponding boolean value (to be inserted in the database).
> |
> | BUT:
> | As it seems the translator is called first, translates the
> | choice into a boolean and the validator fails afterwards :(
> |
> | How can I accomplish this?
> |
> | Thanks in advance!
> | Andreas
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Custom Validator/Translator
Posted by Andreas Bulling <sp...@phoenix.hadiko.de>.
Is nobody out there who can help me with this problem?
That would be very kind as I'm stuck completely with this issue... :(
On 04. Mär 2006 - 12:09:01, Andreas Bulling wrote:
| Hi everybody,
|
| I followed the howto on the wiki to create a custom validator and
| translator: A choice validator which only accepts two different
| string values (like y/n) and a boolean translator which translates
| this choice into corresponding boolean values. Both are configurable
| by use of a parameter passed in the .page file.
|
| The first problem was that (as described in the howto)
|
| <binding name="translator" value="translator:gender,parameter"/>
|
| didn't work - I got an java.lang.reflect.InvocationTargetException.
| And yes, I have a constructor which accepts a String as parameter ;)
|
| Using
|
| <binding name="translator" value="translator:gender,parameter=value"/>
|
| and providing a setter/getter in the translator works.
| Is the first wrong? In this case I won't add my solution to
| the wiki but replace the wrong one.
|
| The second and even bigger problem is that I have a problem with
| the combination of the validator/translator. What I want is
| that first the validator checks if the choice was submitted
| correctly and afterwards this choice is translated in a
| corresponding boolean value (to be inserted in the database).
|
| BUT:
| As it seems the translator is called first, translates the
| choice into a boolean and the validator fails afterwards :(
|
| How can I accomplish this?
|
| Thanks in advance!
| Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org