You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Juan E. Maya" <ma...@gmail.com> on 2009/09/03 18:51:37 UTC

Marker for required fields on bean editor

Hi all!

Is it possible to mark the required fields inside a beaneditor form as
valid? I know i could override the field declaration and put the
marker there but i would like to create something more generic.

I was thinking that a Mixin may get the beaneditor's form to get all
the components in the form, iterate over the validators and add the js
or mark to the ones with a required validator but i am not sure how to
accomplish this. Is it possible at all? Has anybody done such thing?

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


Re: Marker for required fields on bean editor

Posted by "Juan E. Maya" <ma...@gmail.com>.
Awesome :) Thanks a lot!

On Fri, Sep 4, 2009 at 3:04 AM, DH<ni...@gmail.com> wrote:
> I've finished something like that before.
> First create a mixin 'FieldDecorator', then need contribute to the BeanBlockOverrideSource.
> Here is the sample code:
> 1.
> @MixinAfter
> public class FieldDecorator {
>
>  @InjectContainer
>  private AbstractField field;
>
>  @Inject
>    private ComponentResources resources;
>
>  void cleanupRender(MarkupWriter writer)
>    {
>        if (field.isRequired()) {
>            writer.element("font", "color", "red");
>            writer.writeRaw("&nbsp;*&nbsp;");
>            writer.end();
>        }
> }
>
> 2. Contribution, override the default edit block in page PropertyEditBlocks.java.
> public static void contributeBeanBlockOverrideSource(Configuration<BeanBlockContribution> configuration) {
>     configuration.add(new BeanBlockContribution("text", "CustomEditBlocks", "text", true));
>  }
>
> You need write your own CustomEditBlocks.java and CustomEditBlocks.tml to do something like PropertyEditBlocks.java and PropertyEditBlocks.tml, then just put the mixin 'FieldDecorator' there.
>
> DH
> http://www.gaonline.com.cn
>
> ----- Original Message -----
> From: "Juan E. Maya" <ma...@gmail.com>
> To: "Tapestry users" <us...@tapestry.apache.org>
> Sent: Friday, September 04, 2009 1:56 AM
> Subject: Re: Marker for required fields on bean editor
>
>
> Sorry Sebastian, i was not clear enough.
> I want to change the markup of the label when the field has a required
> validator. For example i want to add a CSS class required to the label
> of the required field. or i want to add a * next to the label.
>
> Thanks for ur answer :)
>
> On Thu, Sep 3, 2009 at 7:40 PM, Sebastian
> Hennebrueder<us...@laliluna.de> wrote:
>> Juan E. Maya schrieb:
>>>
>>> Hi all!
>>>
>>> Is it possible to mark the required fields inside a beaneditor form as
>>> valid? I know i could override the field declaration and put the
>>> marker there but i would like to create something more generic.
>>>
>>> I was thinking that a Mixin may get the beaneditor's form to get all
>>> the components in the form, iterate over the validators and add the js
>>> or mark to the ones with a required validator but i am not sure how to
>>> accomplish this. Is it possible at all? Has anybody done such thing?
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>> You are aware of @Validate?
>> http://tapestry.apache.org/tapestry5/guide/validation.html
>>
>>
>> --
>> Best Regards / Viele Grüße
>>
>> Sebastian Hennebrueder
>> -----
>> Software Developer and Trainer for Hibernate / Java Persistence
>> http://www.laliluna.de
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
>
>

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


Re: Marker for required fields on bean editor

Posted by DH <ni...@gmail.com>.
I've finished something like that before.
First create a mixin 'FieldDecorator', then need contribute to the BeanBlockOverrideSource.
Here is the sample code:
1.
@MixinAfter
public class FieldDecorator {

 @InjectContainer
 private AbstractField field;
 
 @Inject
    private ComponentResources resources;
 
 void cleanupRender(MarkupWriter writer)
    {
        if (field.isRequired()) {
            writer.element("font", "color", "red");
            writer.writeRaw("&nbsp;*&nbsp;");
            writer.end();
        }
}

2. Contribution, override the default edit block in page PropertyEditBlocks.java.
public static void contributeBeanBlockOverrideSource(Configuration<BeanBlockContribution> configuration) {
     configuration.add(new BeanBlockContribution("text", "CustomEditBlocks", "text", true));
 }

You need write your own CustomEditBlocks.java and CustomEditBlocks.tml to do something like PropertyEditBlocks.java and PropertyEditBlocks.tml, then just put the mixin 'FieldDecorator' there.

DH
http://www.gaonline.com.cn

----- Original Message ----- 
From: "Juan E. Maya" <ma...@gmail.com>
To: "Tapestry users" <us...@tapestry.apache.org>
Sent: Friday, September 04, 2009 1:56 AM
Subject: Re: Marker for required fields on bean editor


Sorry Sebastian, i was not clear enough.
I want to change the markup of the label when the field has a required
validator. For example i want to add a CSS class required to the label
of the required field. or i want to add a * next to the label.

Thanks for ur answer :)

On Thu, Sep 3, 2009 at 7:40 PM, Sebastian
Hennebrueder<us...@laliluna.de> wrote:
> Juan E. Maya schrieb:
>>
>> Hi all!
>>
>> Is it possible to mark the required fields inside a beaneditor form as
>> valid? I know i could override the field declaration and put the
>> marker there but i would like to create something more generic.
>>
>> I was thinking that a Mixin may get the beaneditor's form to get all
>> the components in the form, iterate over the validators and add the js
>> or mark to the ones with a required validator but i am not sure how to
>> accomplish this. Is it possible at all? Has anybody done such thing?
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> You are aware of @Validate?
> http://tapestry.apache.org/tapestry5/guide/validation.html
>
>
> --
> Best Regards / Viele Grüße
>
> Sebastian Hennebrueder
> -----
> Software Developer and Trainer for Hibernate / Java Persistence
> http://www.laliluna.de
>
>
>
> ---------------------------------------------------------------------
> 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: Marker for required fields on bean editor

Posted by "Juan E. Maya" <ma...@gmail.com>.
Sorry Sebastian, i was not clear enough.
I want to change the markup of the label when the field has a required
validator. For example i want to add a CSS class required to the label
of the required field. or i want to add a * next to the label.

Thanks for ur answer :)

On Thu, Sep 3, 2009 at 7:40 PM, Sebastian
Hennebrueder<us...@laliluna.de> wrote:
> Juan E. Maya schrieb:
>>
>> Hi all!
>>
>> Is it possible to mark the required fields inside a beaneditor form as
>> valid? I know i could override the field declaration and put the
>> marker there but i would like to create something more generic.
>>
>> I was thinking that a Mixin may get the beaneditor's form to get all
>> the components in the form, iterate over the validators and add the js
>> or mark to the ones with a required validator but i am not sure how to
>> accomplish this. Is it possible at all? Has anybody done such thing?
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> You are aware of @Validate?
> http://tapestry.apache.org/tapestry5/guide/validation.html
>
>
> --
> Best Regards / Viele Grüße
>
> Sebastian Hennebrueder
> -----
> Software Developer and Trainer for Hibernate / Java Persistence
> http://www.laliluna.de
>
>
>
> ---------------------------------------------------------------------
> 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: Marker for required fields on bean editor

Posted by Sebastian Hennebrueder <us...@laliluna.de>.
Juan E. Maya schrieb:
> Hi all!
> 
> Is it possible to mark the required fields inside a beaneditor form as
> valid? I know i could override the field declaration and put the
> marker there but i would like to create something more generic.
> 
> I was thinking that a Mixin may get the beaneditor's form to get all
> the components in the form, iterate over the validators and add the js
> or mark to the ones with a required validator but i am not sure how to
> accomplish this. Is it possible at all? Has anybody done such thing?
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
You are aware of @Validate?
http://tapestry.apache.org/tapestry5/guide/validation.html


-- 
Best Regards / Viele Grüße

Sebastian Hennebrueder
-----
Software Developer and Trainer for Hibernate / Java Persistence
http://www.laliluna.de



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