You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Hugo Palma <hu...@gmail.com> on 2010/11/09 17:00:51 UTC

ValidationDecorator using zone updates don't seem to work

I contributed a custom ValidationDecorator which in my case simply adds a
"*" to the label of every required field.

This works fine except when i update a zone with a form. If the form is
rendered on page load the ValidationDecorator is executed as excepted, but
if i update a zone with a form component then the label fields on that form
aren't decorated by my custom ValidationDecorator.
Any idea if this is a bug or maybe i'm doing something wrong ?

Thanks.

Re: ValidationDecorator using zone updates don't seem to work

Posted by Matheus Eduardo Machado Moreira <ma...@gmail.com>.
   Hi!

   Sorry about resurrecting this thread but a have a similar requirement
(render a decoration (eg an '*') in front of labels of every required field)
and some problems.

   I'd like to render the decoration with the same style as the label when
the field is in error. My custom ValidationDecorator renders the decoration
inside a <span> but I'm unable to apply the CSSClassConstants.ERROR class to
it. My code overrides the afterLabel() method and when I try to get the
ValidationTracker from the Environment it results in a NullPointerException:

public RequiredFieldValidationDecorator(String decoration, Environment
environment, MarkupWriter writer) {
    this.decoration = decoration;
    this.environment = environment;
    this.writer = writer;
}

@Override
public void afterLabel(Field field) {
    if (field.isRequired()) {
        writer.element("span");
        if (inError(field)) {
            writer.attributes("class", CSSClassConstants.ERROR);
        }
        writer.write(decoration);
        writer.end();  // span
    }
}

private boolean inError(Field field) {
    ValidationTracker tracker =
*environment*.peekRequired(ValidationTracker.class);
// NPE!
    return tracker.inError(field);
}

   I tried to contribute this ValidationDecorator to MarkupRenderer and
PartialMarkupRenderer services *after* DefaultValidationDecorator. The
decoration is rendered (but not in red when the field is in error) if i
remove the inError() test inside afterLabel(); otherwise the result is a
NPE.

   The other result I'm pursuing is to make this custom ValidationDecorator
to work together with Bean Validation integration. I'd like it to be able to
render an '*' in front of fields that are bound to properties annotated with
JSR 303 annotations.

   I can send any code you think is necessary to solve this problems. Thanks
in advance.

   Atenciosamente,

Matheus Eduardo Machado Moreira
matheus.emm@gmail.com

*Good cooking takes time. If you are made to wait, it is to serve you
better, and to please you.*
Menu do Restaurant Antoine, New Orleans



2010/11/10 Hugo Palma <hu...@gmail.com>

> Thanks Denis, that worked great.
> Still, i think this is more of a workaround than a solution right ?
> Shouldn't this work right out-of-the-box ?
>
> On Wed, Nov 10, 2010 at 12:08, Denis Stepanov <denis.stepanov@gmail.com
> >wrote:
>
> >
> > Try:
> >
> >        public void
> > contributeMarkupRenderer(OrderedConfiguration<MarkupRendererFilter>
> > configuration, final Environment environment) {
> >
> >                MarkupRendererFilter defaultValidationDecorator = new
> > MarkupRendererFilter() {
> >                        public void renderMarkup(MarkupWriter writer,
> > MarkupRenderer renderer) {
> >
>  environment.push(ValidationDecorator.class,
> > new MyValidatorDecorator(environment, writer));
> >                                renderer.renderMarkup(writer);
> >
>  environment.pop(ValidationDecorator.class);
> >                        }
> >                };
> >
> >                configuration.add("MyValidatorDecorator",
> > defaultValidationDecorator, "after:DefaultValidationDecorator");
> >        }
> >
> >        public void
> >
> contributePartialMarkupRenderer(OrderedConfiguration<PartialMarkupRendererFilter>
> > configuration,
> >                final Environment environment) {
> >
> >                PartialMarkupRendererFilter defaultValidationDecorator =
> new
> > PartialMarkupRendererFilter() {
> >                        public void renderMarkup(MarkupWriter writer,
> > JSONObject reply, PartialMarkupRenderer renderer) {
> >
>  environment.push(ValidationDecorator.class,
> > new MyValidatorDecorator(environment, writer));
> >                                renderer.renderMarkup(writer, reply);
> >
>  environment.pop(ValidationDecorator.class);
> >                        }
> >                };
> >
> >                configuration.add("MyValidatorDecorator",
> > defaultValidationDecorator, "after:DefaultValidationDecorator");
> >         }
> >
> > On 10.11.2010, at 12:15, Hugo Palma wrote:
> >
> > > The doesn't seem to be on the render but on the injection of the
> > > ValidationDecorator
> > > into de label component in my case.
> > > I've created an issue for this here
> > > https://issues.apache.org/jira/browse/TAP5-1339
> > >
> > > On Wed, Nov 10, 2010 at 10:20, Denis Stepanov <
> denis.stepanov@gmail.com
> > >wrote:
> > >
> > >> Ajax response uses PartialMarkupRenderer via
> > >> contributePartialMarkupRenderer.
> > >>
> > >> Denis
> > >>
> > >> On 9.11.2010, at 17:00, Hugo Palma wrote:
> > >>
> > >>> I contributed a custom ValidationDecorator which in my case simply
> adds
> > a
> > >>> "*" to the label of every required field.
> > >>>
> > >>> This works fine except when i update a zone with a form. If the form
> is
> > >>> rendered on page load the ValidationDecorator is executed as
> excepted,
> > >> but
> > >>> if i update a zone with a form component then the label fields on
> that
> > >> form
> > >>> aren't decorated by my custom ValidationDecorator.
> > >>> Any idea if this is a bug or maybe i'm doing something wrong ?
> > >>>
> > >>> Thanks.
> > >>
> > >>
> > >> ---------------------------------------------------------------------
> > >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > >> For additional commands, e-mail: users-help@tapestry.apache.org
> > >>
> > >>
> > >
> > >
> > > --
> > >
> > > LinkedIn <http://www.linkedin.com/in/hugopalma>
> > > Twitter<http://twitter.com/hugompalma>
> >
> >
>
>
> --
>
> LinkedIn <http://www.linkedin.com/in/hugopalma>
> Twitter<http://twitter.com/hugompalma>
>

Re: ValidationDecorator using zone updates don't seem to work

Posted by Hugo Palma <hu...@gmail.com>.
Thanks Denis, that worked great.
Still, i think this is more of a workaround than a solution right ?
Shouldn't this work right out-of-the-box ?

On Wed, Nov 10, 2010 at 12:08, Denis Stepanov <de...@gmail.com>wrote:

>
> Try:
>
>        public void
> contributeMarkupRenderer(OrderedConfiguration<MarkupRendererFilter>
> configuration, final Environment environment) {
>
>                MarkupRendererFilter defaultValidationDecorator = new
> MarkupRendererFilter() {
>                        public void renderMarkup(MarkupWriter writer,
> MarkupRenderer renderer) {
>                                environment.push(ValidationDecorator.class,
> new MyValidatorDecorator(environment, writer));
>                                renderer.renderMarkup(writer);
>                                environment.pop(ValidationDecorator.class);
>                        }
>                };
>
>                configuration.add("MyValidatorDecorator",
> defaultValidationDecorator, "after:DefaultValidationDecorator");
>        }
>
>        public void
> contributePartialMarkupRenderer(OrderedConfiguration<PartialMarkupRendererFilter>
> configuration,
>                final Environment environment) {
>
>                PartialMarkupRendererFilter defaultValidationDecorator = new
> PartialMarkupRendererFilter() {
>                        public void renderMarkup(MarkupWriter writer,
> JSONObject reply, PartialMarkupRenderer renderer) {
>                                environment.push(ValidationDecorator.class,
> new MyValidatorDecorator(environment, writer));
>                                renderer.renderMarkup(writer, reply);
>                                environment.pop(ValidationDecorator.class);
>                        }
>                };
>
>                configuration.add("MyValidatorDecorator",
> defaultValidationDecorator, "after:DefaultValidationDecorator");
>         }
>
> On 10.11.2010, at 12:15, Hugo Palma wrote:
>
> > The doesn't seem to be on the render but on the injection of the
> > ValidationDecorator
> > into de label component in my case.
> > I've created an issue for this here
> > https://issues.apache.org/jira/browse/TAP5-1339
> >
> > On Wed, Nov 10, 2010 at 10:20, Denis Stepanov <denis.stepanov@gmail.com
> >wrote:
> >
> >> Ajax response uses PartialMarkupRenderer via
> >> contributePartialMarkupRenderer.
> >>
> >> Denis
> >>
> >> On 9.11.2010, at 17:00, Hugo Palma wrote:
> >>
> >>> I contributed a custom ValidationDecorator which in my case simply adds
> a
> >>> "*" to the label of every required field.
> >>>
> >>> This works fine except when i update a zone with a form. If the form is
> >>> rendered on page load the ValidationDecorator is executed as excepted,
> >> but
> >>> if i update a zone with a form component then the label fields on that
> >> form
> >>> aren't decorated by my custom ValidationDecorator.
> >>> Any idea if this is a bug or maybe i'm doing something wrong ?
> >>>
> >>> Thanks.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >>
> >>
> >
> >
> > --
> >
> > LinkedIn <http://www.linkedin.com/in/hugopalma>
> > Twitter<http://twitter.com/hugompalma>
>
>


-- 

LinkedIn <http://www.linkedin.com/in/hugopalma>
Twitter<http://twitter.com/hugompalma>

Re: ValidationDecorator using zone updates don't seem to work

Posted by Denis Stepanov <de...@gmail.com>.
Try:

	public void contributeMarkupRenderer(OrderedConfiguration<MarkupRendererFilter> configuration, final Environment environment) {

		MarkupRendererFilter defaultValidationDecorator = new MarkupRendererFilter() {
			public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
				environment.push(ValidationDecorator.class, new MyValidatorDecorator(environment, writer));
				renderer.renderMarkup(writer);
				environment.pop(ValidationDecorator.class);
			}
		};

		configuration.add("MyValidatorDecorator", defaultValidationDecorator, "after:DefaultValidationDecorator");
	}

	public void contributePartialMarkupRenderer(OrderedConfiguration<PartialMarkupRendererFilter> configuration,
		final Environment environment) {

		PartialMarkupRendererFilter defaultValidationDecorator = new PartialMarkupRendererFilter() {
			public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer) {
				environment.push(ValidationDecorator.class, new MyValidatorDecorator(environment, writer));
				renderer.renderMarkup(writer, reply);
				environment.pop(ValidationDecorator.class);
			}
		};

		configuration.add("MyValidatorDecorator", defaultValidationDecorator, "after:DefaultValidationDecorator");
	}

On 10.11.2010, at 12:15, Hugo Palma wrote:

> The doesn't seem to be on the render but on the injection of the
> ValidationDecorator
> into de label component in my case.
> I've created an issue for this here
> https://issues.apache.org/jira/browse/TAP5-1339
> 
> On Wed, Nov 10, 2010 at 10:20, Denis Stepanov <de...@gmail.com>wrote:
> 
>> Ajax response uses PartialMarkupRenderer via
>> contributePartialMarkupRenderer.
>> 
>> Denis
>> 
>> On 9.11.2010, at 17:00, Hugo Palma wrote:
>> 
>>> I contributed a custom ValidationDecorator which in my case simply adds a
>>> "*" to the label of every required field.
>>> 
>>> This works fine except when i update a zone with a form. If the form is
>>> rendered on page load the ValidationDecorator is executed as excepted,
>> but
>>> if i update a zone with a form component then the label fields on that
>> form
>>> aren't decorated by my custom ValidationDecorator.
>>> Any idea if this is a bug or maybe i'm doing something wrong ?
>>> 
>>> Thanks.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
>> 
> 
> 
> -- 
> 
> LinkedIn <http://www.linkedin.com/in/hugopalma>
> Twitter<http://twitter.com/hugompalma>


Re: ValidationDecorator using zone updates don't seem to work

Posted by Hugo Palma <hu...@gmail.com>.
The doesn't seem to be on the render but on the injection of the
ValidationDecorator
into de label component in my case.
I've created an issue for this here
https://issues.apache.org/jira/browse/TAP5-1339

On Wed, Nov 10, 2010 at 10:20, Denis Stepanov <de...@gmail.com>wrote:

> Ajax response uses PartialMarkupRenderer via
> contributePartialMarkupRenderer.
>
> Denis
>
> On 9.11.2010, at 17:00, Hugo Palma wrote:
>
> > I contributed a custom ValidationDecorator which in my case simply adds a
> > "*" to the label of every required field.
> >
> > This works fine except when i update a zone with a form. If the form is
> > rendered on page load the ValidationDecorator is executed as excepted,
> but
> > if i update a zone with a form component then the label fields on that
> form
> > aren't decorated by my custom ValidationDecorator.
> > Any idea if this is a bug or maybe i'm doing something wrong ?
> >
> > Thanks.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 

LinkedIn <http://www.linkedin.com/in/hugopalma>
Twitter<http://twitter.com/hugompalma>

Re: ValidationDecorator using zone updates don't seem to work

Posted by Denis Stepanov <de...@gmail.com>.
Ajax response uses PartialMarkupRenderer via contributePartialMarkupRenderer.

Denis

On 9.11.2010, at 17:00, Hugo Palma wrote:

> I contributed a custom ValidationDecorator which in my case simply adds a
> "*" to the label of every required field.
> 
> This works fine except when i update a zone with a form. If the form is
> rendered on page load the ValidationDecorator is executed as excepted, but
> if i update a zone with a form component then the label fields on that form
> aren't decorated by my custom ValidationDecorator.
> Any idea if this is a bug or maybe i'm doing something wrong ?
> 
> Thanks.


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