You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ilya Obshadko <il...@gmail.com> on 2013/10/04 08:51:59 UTC

context-dependent validator

Hello,

Is that possible to create a custom validator that is context-dependent?
That is, I want validation logic (including client-side JS) to depend on
actual component data.

I have checked http://wiki.apache.org/tapestry/Tapestry5HowToAddValidators,
it's pretty clear how to do that, but I don't have any idea how do I inject
actual component data into validator when needed.

Thanks in advance!

-- 
Ilya Obshadko

Re: context-dependent validator

Posted by Ilya Obshadko <il...@gmail.com>.
That makes sense, thank you!


On Sat, Oct 5, 2013 at 12:53 AM, Barry Books <tr...@gmail.com> wrote:

> It has this method
>
> *public* *void* render(Field field, String message, MarkupWriter writer,
> FormSupport formSupport) {
>
>
>  }
>
>
> which gives you the field, the form and a writer to the element. I use it
> to write data- attributes into the html markup and then the javascript can
> access them. I think your simple example could be solved by either method
> but with a validator you could write min="1" and max="10" into the element
> and then use javascript enforce that. The translator could also support
> this on the server side when it parses the client data.
>
>
> On Fri, Oct 4, 2013 at 10:24 AM, Ilya Obshadko <ilya.obshadko@gmail.com
> >wrote:
>
> > On Fri, Oct 4, 2013 at 8:17 PM, Barry Books <tr...@gmail.com> wrote:
> >
> > > You might be able to do this with a translator instead of a validator.
> > They
> > > are really for converting data but you can also throw validation
> > > exceptions, access the current field and add data to the html element.
> > >
> >
> > Does translator really have JS hooks I could use?
> >
> >
> > > On Fri, Oct 4, 2013 at 1:51 AM, Ilya Obshadko <ilya.obshadko@gmail.com
> > > >wrote:
> > >
> > > > Hello,
> > > >
> > > > Is that possible to create a custom validator that is
> > context-dependent?
> > > > That is, I want validation logic (including client-side JS) to depend
> > on
> > > > actual component data.
> > > >
> > > > I have checked
> > > http://wiki.apache.org/tapestry/Tapestry5HowToAddValidators
> > > > ,
> > > > it's pretty clear how to do that, but I don't have any idea how do I
> > > inject
> > > > actual component data into validator when needed.
> > > >
> > > > Thanks in advance!
> > > >
> > > > --
> > > > Ilya Obshadko
> > > >
> > >
> >
> >
> >
> > --
> > Ilya Obshadko
> >
>



-- 
Ilya Obshadko

Re: context-dependent validator

Posted by Barry Books <tr...@gmail.com>.
It has this method

*public* *void* render(Field field, String message, MarkupWriter writer,
FormSupport formSupport) {


 }


which gives you the field, the form and a writer to the element. I use it
to write data- attributes into the html markup and then the javascript can
access them. I think your simple example could be solved by either method
but with a validator you could write min="1" and max="10" into the element
and then use javascript enforce that. The translator could also support
this on the server side when it parses the client data.


On Fri, Oct 4, 2013 at 10:24 AM, Ilya Obshadko <il...@gmail.com>wrote:

> On Fri, Oct 4, 2013 at 8:17 PM, Barry Books <tr...@gmail.com> wrote:
>
> > You might be able to do this with a translator instead of a validator.
> They
> > are really for converting data but you can also throw validation
> > exceptions, access the current field and add data to the html element.
> >
>
> Does translator really have JS hooks I could use?
>
>
> > On Fri, Oct 4, 2013 at 1:51 AM, Ilya Obshadko <ilya.obshadko@gmail.com
> > >wrote:
> >
> > > Hello,
> > >
> > > Is that possible to create a custom validator that is
> context-dependent?
> > > That is, I want validation logic (including client-side JS) to depend
> on
> > > actual component data.
> > >
> > > I have checked
> > http://wiki.apache.org/tapestry/Tapestry5HowToAddValidators
> > > ,
> > > it's pretty clear how to do that, but I don't have any idea how do I
> > inject
> > > actual component data into validator when needed.
> > >
> > > Thanks in advance!
> > >
> > > --
> > > Ilya Obshadko
> > >
> >
>
>
>
> --
> Ilya Obshadko
>

Re: context-dependent validator

Posted by Ilya Obshadko <il...@gmail.com>.
On Fri, Oct 4, 2013 at 8:17 PM, Barry Books <tr...@gmail.com> wrote:

> You might be able to do this with a translator instead of a validator. They
> are really for converting data but you can also throw validation
> exceptions, access the current field and add data to the html element.
>

Does translator really have JS hooks I could use?


> On Fri, Oct 4, 2013 at 1:51 AM, Ilya Obshadko <ilya.obshadko@gmail.com
> >wrote:
>
> > Hello,
> >
> > Is that possible to create a custom validator that is context-dependent?
> > That is, I want validation logic (including client-side JS) to depend on
> > actual component data.
> >
> > I have checked
> http://wiki.apache.org/tapestry/Tapestry5HowToAddValidators
> > ,
> > it's pretty clear how to do that, but I don't have any idea how do I
> inject
> > actual component data into validator when needed.
> >
> > Thanks in advance!
> >
> > --
> > Ilya Obshadko
> >
>



-- 
Ilya Obshadko

Re: context-dependent validator

Posted by Barry Books <tr...@gmail.com>.
You might be able to do this with a translator instead of a validator. They
are really for converting data but you can also throw validation
exceptions, access the current field and add data to the html element.


On Fri, Oct 4, 2013 at 1:51 AM, Ilya Obshadko <il...@gmail.com>wrote:

> Hello,
>
> Is that possible to create a custom validator that is context-dependent?
> That is, I want validation logic (including client-side JS) to depend on
> actual component data.
>
> I have checked http://wiki.apache.org/tapestry/Tapestry5HowToAddValidators
> ,
> it's pretty clear how to do that, but I don't have any idea how do I inject
> actual component data into validator when needed.
>
> Thanks in advance!
>
> --
> Ilya Obshadko
>

Re: context-dependent validator

Posted by Ilya Obshadko <il...@gmail.com>.
On Fri, Oct 4, 2013 at 9:25 PM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Fri, 04 Oct 2013 03:51:59 -0300, Ilya Obshadko <il...@gmail.com>
> wrote:
>
>  Hello,
>>
>
> Hi!
>
>
>  I have checked http://wiki.apache.org/**tapestry/**
>> Tapestry5HowToAddValidators<http://wiki.apache.org/tapestry/Tapestry5HowToAddValidators>
>> ,
>> it's pretty clear how to do that, but I don't have any idea how do I
>> inject actual component data into validator when needed.
>>
>
> Which data? From the component being validated? It comes in the second
> parameter of the Validator.validate() method.


Not actually. From component containing the field being validated and
actually defining validation context.

Suppose you have several input fields where you enter rankings in range
between 1 and number of items being ranked. So if you have 10 items, values
from 1 to 10 are valid, while 11 is invalid.

I want to have this checked at validator level both on server and client
side.


>
>
> --
> Thiago H. de Paula Figueiredo
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<us...@tapestry.apache.org>
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Ilya Obshadko

Re: context-dependent validator

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Fri, 04 Oct 2013 03:51:59 -0300, Ilya Obshadko  
<il...@gmail.com> wrote:

> Hello,

Hi!

> I have checked  
> http://wiki.apache.org/tapestry/Tapestry5HowToAddValidators,
> it's pretty clear how to do that, but I don't have any idea how do I  
> inject actual component data into validator when needed.

Which data? From the component being validated? It comes in the second  
parameter of the Validator.validate() method.

-- 
Thiago H. de Paula Figueiredo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org