You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Alf Felis <Al...@gmx.de> on 2010/03/30 18:53:35 UTC

[Tobago] Using validator in custom tag

Hi all,

I try to use a validator dependent on a property within a custom tag class.

My class extends TagSupport and overwrites the doStartTag() method.
In this method I add a validator depending on a property (see below).

First the property is "false" and no validator will be added to the inExtensionTag. Now (next access to the page) the property will change to "true" and the output "Setting validator!" shows me, that the validator has been set. But the validator will never be called!

If I always add the validator (not depending on the property), everything works fine. The validator will be called on submit.

What is wrong with my approach?
Is there another possibility to do what I want?

Example:

    @Override
    public int doStartTag() throws JspException {
        InExtensionTag inExtensionTag = new InExtensionTag();
        inExtensionTag.setPageContext(pageContext);
        inExtensionTag.setParent(getParent());
        inExtensionTag.setId(id);
        inExtensionTag.setLabel(label);
        inExtensionTag.setValue(value);
        if (isValidationEnabled()) {
            System.out.println("Setting validator!");
            inExtensionTag.setValidator("#validator.validate}");
        }
        inExtensionTag.doStartTag();
        inExtensionTag.doEndTag();
        return super.doStartTag();
    }


Best regards,

Alf

-- 
GMX DSL: Internet, Telefon und Entertainment für nur 19,99 EUR/mtl.!
http://portal.gmx.net/de/go/dsl02

Re: [Tobago] Using validator in custom tag

Posted by Now I find myself in question <vi...@gmail.com>.
yes it should be like..

inExtensionTag.setValidator("#*{*validator.validate*}*");

Thanks,
Vinod

On Wed, Mar 31, 2010 at 12:55 PM, Helmut Swaczinna
<my...@wlp-systems.de>wrote:

> Hi,
>
> there's no '{' in "#validator.validate}");
>
> Regards
>
> Helmut
>
>
> Am 30.03.2010 18:53, schrieb Alf Felis:
>
>  Hi all,
>>
>> I try to use a validator dependent on a property within a custom tag
>> class.
>>
>> My class extends TagSupport and overwrites the doStartTag() method.
>> In this method I add a validator depending on a property (see below).
>>
>> First the property is "false" and no validator will be added to the
>> inExtensionTag. Now (next access to the page) the property will change to
>> "true" and the output "Setting validator!" shows me, that the validator has
>> been set. But the validator will never be called!
>>
>> If I always add the validator (not depending on the property), everything
>> works fine. The validator will be called on submit.
>>
>> What is wrong with my approach?
>> Is there another possibility to do what I want?
>>
>> Example:
>>
>>     @Override
>>     public int doStartTag() throws JspException {
>>         InExtensionTag inExtensionTag = new InExtensionTag();
>>         inExtensionTag.setPageContext(pageContext);
>>         inExtensionTag.setParent(getParent());
>>         inExtensionTag.setId(id);
>>         inExtensionTag.setLabel(label);
>>         inExtensionTag.setValue(value);
>>         if (isValidationEnabled()) {
>>             System.out.println("Setting validator!");
>>             inExtensionTag.setValidator("#validator.validate}");
>>         }
>>         inExtensionTag.doStartTag();
>>         inExtensionTag.doEndTag();
>>         return super.doStartTag();
>>     }
>>
>>
>> Best regards,
>>
>> Alf
>>
>>

Re: [Tobago] Using validator in custom tag

Posted by Helmut Swaczinna <my...@wlp-systems.de>.
Hi,

there's no '{' in "#validator.validate}");

Regards

Helmut


Am 30.03.2010 18:53, schrieb Alf Felis:
> Hi all,
>
> I try to use a validator dependent on a property within a custom tag class.
>
> My class extends TagSupport and overwrites the doStartTag() method.
> In this method I add a validator depending on a property (see below).
>
> First the property is "false" and no validator will be added to the inExtensionTag. Now (next access to the page) the property will change to "true" and the output "Setting validator!" shows me, that the validator has been set. But the validator will never be called!
>
> If I always add the validator (not depending on the property), everything works fine. The validator will be called on submit.
>
> What is wrong with my approach?
> Is there another possibility to do what I want?
>
> Example:
>
>      @Override
>      public int doStartTag() throws JspException {
>          InExtensionTag inExtensionTag = new InExtensionTag();
>          inExtensionTag.setPageContext(pageContext);
>          inExtensionTag.setParent(getParent());
>          inExtensionTag.setId(id);
>          inExtensionTag.setLabel(label);
>          inExtensionTag.setValue(value);
>          if (isValidationEnabled()) {
>              System.out.println("Setting validator!");
>              inExtensionTag.setValidator("#validator.validate}");
>          }
>          inExtensionTag.doStartTag();
>          inExtensionTag.doEndTag();
>          return super.doStartTag();
>      }
>
>
> Best regards,
>
> Alf
>