You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Dave Rathnow <dr...@telus.net> on 2006/10/10 14:15:21 UTC

Validation questions: components and messages

I have written a component that contains text fields that need to be validated
when a page is submitted but I can't figure out how component validation
hooks into Tapestry's validation framework.  I can access my validation delegate
in my page component but how can I get the validation delegate from my
component?

Also, is there an easy way to get the individual error messages from the
validation delegate?  I want to put individual validation errors messages
next to each field rather than have a single message at the top of the page
and then ** beside each of the errored field.

Thanks,
Dave.

Re: Validation questions: components and messages

Posted by Ron Piterman <rp...@gmx.net>.
Yes - you can do much with the delegate :)
BTW - consider using CSS for this instead of adding elements , it might
be more elegant and easier to maintain...

Cheers,
Ron

Reto Hotz wrote:
> Hi,
> 
> On 10/10/06, Ron Piterman <rp...@gmx.net> wrote:
>> Dave Rathnow wrote:
>> > Also, is there an easy way to get the individual error messages from
>> the
>> > validation delegate?
>>
>> In such a case you need to create your own class, extending the standard
>> validation delegate. There are methods which allow the delegate to hook
>> up into the rendering of fields and their labels, so you can do just
>> what you described.
> 
> We also wrote our own validation delegate with nice error-icons.
> Somehow like this:
> 
> public class MyValidationDelegate extends ValidationDelegate {
> 
>    public void writeAttributes(IMarkupWriter writer, IRequestCycle
> cycle, IFormComponent component, IValidator validator) {
>        if (isInError())
>            writer.attribute("class", "validationerror");
>    }
> 
>    public void writeSuffix(IMarkupWriter writer, IRequestCycle cycle,
> IFormComponent component, IValidator validator) {
>        if (isInError()) {
>            writer.print(" ");
>            writer.beginEmpty("img");
>            writer.attribute("src", "warning_small.gif");
>        }
>    }
> 
>    public void writeLabelPrefix(IFormComponent component,
> IMarkupWriter writer, IRequestCycle cycle) {
>        if (isInError(component)) {
>            writer.begin("span");
>            writer.attribute("class", "label-error");
>        }
>    }
> 
>    public void writeLabelSuffix(IFormComponent component,
> IMarkupWriter writer, IRequestCycle cycle) {
>        if (isInError(component))
>            writer.end(); // <span>
>    }
> }
> 
> 
> HTH
> 
> Greetings
> Reto
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 


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


Re: Validation questions: components and messages

Posted by Reto Hotz <re...@gmail.com>.
Hi,

On 10/10/06, Ron Piterman <rp...@gmx.net> wrote:
> Dave Rathnow wrote:
> > Also, is there an easy way to get the individual error messages from the
> > validation delegate?
>
> In such a case you need to create your own class, extending the standard
> validation delegate. There are methods which allow the delegate to hook
> up into the rendering of fields and their labels, so you can do just
> what you described.

We also wrote our own validation delegate with nice error-icons.
Somehow like this:

public class MyValidationDelegate extends ValidationDelegate {

    public void writeAttributes(IMarkupWriter writer, IRequestCycle
cycle, IFormComponent component, IValidator validator) {
        if (isInError())
            writer.attribute("class", "validationerror");
    }

    public void writeSuffix(IMarkupWriter writer, IRequestCycle cycle,
IFormComponent component, IValidator validator) {
        if (isInError()) {
            writer.print(" ");
            writer.beginEmpty("img");
            writer.attribute("src", "warning_small.gif");
        }
    }

    public void writeLabelPrefix(IFormComponent component,
IMarkupWriter writer, IRequestCycle cycle) {
        if (isInError(component)) {
            writer.begin("span");
            writer.attribute("class", "label-error");
        }
    }

    public void writeLabelSuffix(IFormComponent component,
IMarkupWriter writer, IRequestCycle cycle) {
        if (isInError(component))
            writer.end(); // <span>
    }
}


HTH

Greetings
Reto

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


Re: Validation questions: components and messages

Posted by Ron Piterman <rp...@gmx.net>.
Dave Rathnow wrote:
> I have written a component that contains text fields that need to be validated
> when a page is submitted but I can't figure out how component validation
> hooks into Tapestry's validation framework.  I can access my validation delegate
> in my page component but how can I get the validation delegate from my
> component?

You use per Form one instance of validation delegate. It tracks the
validation errors which the components report. This happends from
itself, you just need to define the validators on the fields.

> 
> Also, is there an easy way to get the individual error messages from the
> validation delegate?  I want to put individual validation errors messages
> next to each field rather than have a single message at the top of the page
> and then ** beside each of the errored field.

In such a case you need to create your own class, extending the standard
validation delegate. There are methods which allow the delegate to hook
up into the rendering of fields and their labels, so you can do just
what you described.

> 
> Thanks,
> Dave.
>

Please,
Ron



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