You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "superjoerch@gmx.de" <su...@gmx.de> on 2008/07/10 09:43:37 UTC

How to set a converter default property?

Hi, i try to set a default property for a converter in this way:
<validator>
    <validator-id>xyValidtor</validator-name>
    <validator-class>com.xy.XyValidator</validator-class>
    <property>
       <property-name>length</property-name>
       <property-class>java.lang.Integer</property>
       <default-value>40</default-value>
    </property>
</validator>

I expected that setter-Methode of my Member length in the 
XyValidator-Class will called, but only the
default Constructor is called, so why fails my setting of a 
Default-Property?

Can someone help me please!?

-Jörg



Re: How to set a converter default property?

Posted by Volker Weber <v....@inexso.de>.
Hi,

don't you get ParseExceptions on deploy?

I don't  know if this is the problem, i never used property on validator,
but my idea complains about:

2008/7/10 superjoerch@gmx.de <su...@gmx.de>:
> Hi, i try to set a default property for a converter in this way:
> <validator>
>   <validator-id>xyValidtor</validator-name>
                    ^^                                 ^^^^^

>   <validator-class>com.xy.XyValidator</validator-class>
>   <property>
>      <property-name>length</property-name>
>      <property-class>java.lang.Integer</property>
                       ^^^^^^                                        ^

>      <default-value>40</default-value>
>   </property>
> </validator>
>
> I expected that setter-Methode of my Member length in the XyValidator-Class
> will called, but only the
> default Constructor is called, so why fails my setting of a
> Default-Property?
>
> Can someone help me please!?
>
> -Jörg
>
>
>

Regards,
   Volker

-- 
inexso - information exchange solutions GmbH
Bismarckstraße 13 | 26122 Oldenburg
Tel.: +49 441 4082 356 |
FAX: +49 441 4082 355 | www.inexso.de

RE: How to set a converter default property?

Posted by Guy Bashan <gu...@gmail.com>.
Hi,

 

Don't you prefer to put this information through a proper configuration
mechanism rather than faces configuration file:

 

For example, you will have a: conf.properties file under WEB-INF dir.

With the key value pair: name.max.length=40

 

Then in the code:

myConfiSingleton.instance().getInt("name.max.length")

 

In my opinion it is easier to manage configuration data when it is
centralized in one place and not distributed all over all sort of
configuration files from different frameworks.

In addition you may want to use this property in other cases then only
validator.

 

This is only my opinion… ;-)

Guy.

 

From: superjoerch@gmx.de [mailto:superjoerch@gmx.de] 
Sent: Thursday, July 10, 2008 11:50 AM
To: MyFaces Discussion
Subject: Re: How to set a converter default property?

 

So, i can use my validator only for the length 40, but if i can set a
default-value, i can use one class with many length values. 
I only have to change the id and the default-value in the faces-config:



<validator>
   <validator-id>xyValidtor40</validator-name>
   <validator-class>com.xy.XyValidator</validator-class>
   <property>
      <property-name>length</property-name>
      <property-class>java.lang.Integer</property>
      <default-value>40</default-value>
   </property>
</validator>
<validator>
   <validator-id>xyValidtor80</validator-name>
   <validator-class>com.xy.XyValidator</validator-class>
   <property>
      <property-name>length</property-name>
      <property-class>java.lang.Integer</property>
      <default-value>80</default-value>
   </property>
</validator>

and so on.

-Jörg

Guy Bashan schrieb: 

Hi,
 
Why not simply do:
 
Public class MyConverter implements Converter
{
        private static final int LENGTH = 40;
...
...
}
 
 
Guy.
-----Original Message-----
From: simon.kitching@chello.at [mailto:simon.kitching@chello.at] 
Sent: Thursday, July 10, 2008 10:57 AM
To: MyFaces Discussion
Subject: Re: How to set a converter default property?
 
superjoerch@gmx.de schrieb:
  

Hi, i try to set a default property for a converter in this way:
<validator>
   <validator-id>xyValidtor</validator-name>
   <validator-class>com.xy.XyValidator</validator-class>
   <property>
      <property-name>length</property-name>
      <property-class>java.lang.Integer</property>
      <default-value>40</default-value>
   </property>
</validator>
 
I expected that setter-Methode of my Member length in the 
XyValidator-Class will called, but only the
default Constructor is called, so why fails my setting of a 
Default-Property?
 
    

The JSF standard does not support this. When defining a validator in a 
faces-config.xml file, the only supported xml elements are validator-id 
and validator-class.
 
What you can do is use the validator attribute available on all input 
elements:
 <h:inputText validator="#{....}" .../>
 
That EL expression can then get an object from your "managed beans" 
definitions, which does support setting properties etc.
 
Regards, Simon
 
 
  

 


Re: How to set a converter default property?

Posted by "superjoerch@gmx.de" <su...@gmx.de>.
So, i can use my validator only for the length 40, but if i can set a 
default-value, i can use one class with many length values.
I only have to change the id and the default-value in the faces-config:

<validator>
   <validator-id>xyValidtor40</validator-name>
   <validator-class>com.xy.XyValidator</validator-class>
   <property>
      <property-name>length</property-name>
      <property-class>java.lang.Integer</property>
      <default-value>40</default-value>
   </property>
</validator>

<validator>
   <validator-id>xyValidtor80</validator-name>
   <validator-class>com.xy.XyValidator</validator-class>
   <property>
      <property-name>length</property-name>
      <property-class>java.lang.Integer</property>
      <default-value>80</default-value>
   </property>
</validator>

and so on.

-Jörg

Guy Bashan schrieb:
> Hi,
>
> Why not simply do:
>
> Public class MyConverter implements Converter
> {
> 	private static final int LENGTH = 40;
> ...
> ...
> }
>
>
> Guy.
> -----Original Message-----
> From: simon.kitching@chello.at [mailto:simon.kitching@chello.at] 
> Sent: Thursday, July 10, 2008 10:57 AM
> To: MyFaces Discussion
> Subject: Re: How to set a converter default property?
>
> superjoerch@gmx.de schrieb:
>   
>> Hi, i try to set a default property for a converter in this way:
>> <validator>
>>    <validator-id>xyValidtor</validator-name>
>>    <validator-class>com.xy.XyValidator</validator-class>
>>    <property>
>>       <property-name>length</property-name>
>>       <property-class>java.lang.Integer</property>
>>       <default-value>40</default-value>
>>    </property>
>> </validator>
>>
>> I expected that setter-Methode of my Member length in the 
>> XyValidator-Class will called, but only the
>> default Constructor is called, so why fails my setting of a 
>> Default-Property?
>>
>>     
> The JSF standard does not support this. When defining a validator in a 
> faces-config.xml file, the only supported xml elements are validator-id 
> and validator-class.
>
> What you can do is use the validator attribute available on all input 
> elements:
>  <h:inputText validator="#{....}" .../>
>
> That EL expression can then get an object from your "managed beans" 
> definitions, which does support setting properties etc.
>
> Regards, Simon
>
>
>   


RE: How to set a converter default property?

Posted by Guy Bashan <gu...@gmail.com>.
Hi,

Why not simply do:

Public class MyConverter implements Converter
{
	private static final int LENGTH = 40;
...
...
}


Guy.
-----Original Message-----
From: simon.kitching@chello.at [mailto:simon.kitching@chello.at] 
Sent: Thursday, July 10, 2008 10:57 AM
To: MyFaces Discussion
Subject: Re: How to set a converter default property?

superjoerch@gmx.de schrieb:
> Hi, i try to set a default property for a converter in this way:
> <validator>
>    <validator-id>xyValidtor</validator-name>
>    <validator-class>com.xy.XyValidator</validator-class>
>    <property>
>       <property-name>length</property-name>
>       <property-class>java.lang.Integer</property>
>       <default-value>40</default-value>
>    </property>
> </validator>
>
> I expected that setter-Methode of my Member length in the 
> XyValidator-Class will called, but only the
> default Constructor is called, so why fails my setting of a 
> Default-Property?
>
The JSF standard does not support this. When defining a validator in a 
faces-config.xml file, the only supported xml elements are validator-id 
and validator-class.

What you can do is use the validator attribute available on all input 
elements:
 <h:inputText validator="#{....}" .../>

That EL expression can then get an object from your "managed beans" 
definitions, which does support setting properties etc.

Regards, Simon


Re: How to set a converter default property?

Posted by "superjoerch@gmx.de" <su...@gmx.de>.
Hi Simon, that's right i have the problem with a validator not with a 
converter.
-Jörg

simon.kitching@chello.at schrieb:
> Volker Weber schrieb:
>> Hi simon,
>>
>> 2008/7/10 simon.kitching@chello.at <si...@chello.at>:
>>
>> [...]
>>  
>>> The JSF standard does not support this. When defining a validator in a
>>> faces-config.xml file, the only supported xml elements are 
>>> validator-id and
>>> validator-class.
>>>     
>> [...]
>>
>> The http://java.sun.com/dtd/web-facesconfig_1_1.dtd support property
>> on validator:
>>
>> <!--
>>     The "validator" element represents a concrete Validator 
>> implementation
>>     class that should be registered under the specified validator 
>> identifier.
>>     Validator identifiers must be unique within the entire web 
>> application.
>>
>>     Nested "attribute" elements identify generic attributes that may be
>>     configured on the corresponding UIComponent in order to affect the
>>     operation of the Validator.  Nested "property" elements identify 
>> JavaBeans
>>     properties of the Validator implementation class that may be 
>> configured
>>     to affect the operation of the Validator.
>> -->
>> <!ELEMENT validator       (description*, display-name*, icon*,
>> validator-id, validator-class, attribute*, property*)>
>>   
>
> Ah, I didn't know that.
>
> It appears that whoever implemented the faces-config parsing didn't 
> know that either. Here's code from 
> DigesterFacesConfigUnmarshallerImpl.java (core/trunk12):
>
>        digester.addCallMethod("faces-config/validator", 
> "addValidator", 2);
>        digester.addCallParam("faces-config/validator/validator-id", 0);
>        digester.addCallParam("faces-config/validator/validator-class", 
> 1);
>
> So it looks like at the moment the only supported child elements of 
> <validator> are validator-id and validator-class.
>
> Note that in the same method, the <converter> tag does appear to be 
> handled correctly, with digester rules existing for nested attribute 
> and property elements.
>
> Just by the way, the subject on the original email was about 
> "converter", but the example was about "validator". I presume the 
> problem really is with a validator....
>
> Regards,
> Simon
>
>



Re: How to set a converter default property?

Posted by "superjoerch@gmx.de" <su...@gmx.de>.
Ok, thank you Simon.

-Jörg

simon.kitching@chello.at schrieb:
> simon.kitching@chello.at schrieb:
>> Volker Weber schrieb:
>>> [...]
>>>
>>> The http://java.sun.com/dtd/web-facesconfig_1_1.dtd support property
>>> on validator:
>>>
>>> <!--
>>>     The "validator" element represents a concrete Validator 
>>> implementation
>>>     class that should be registered under the specified validator 
>>> identifier.
>>>     Validator identifiers must be unique within the entire web 
>>> application.
>>>
>>>     Nested "attribute" elements identify generic attributes that may be
>>>     configured on the corresponding UIComponent in order to affect the
>>>     operation of the Validator.  Nested "property" elements identify 
>>> JavaBeans
>>>     properties of the Validator implementation class that may be 
>>> configured
>>>     to affect the operation of the Validator.
>>> -->
>>> <!ELEMENT validator       (description*, display-name*, icon*,
>>> validator-id, validator-class, attribute*, property*)>
>>>   
>>
>> It appears that whoever implemented the faces-config parsing didn't 
>> know that either. Here's code from 
>> DigesterFacesConfigUnmarshallerImpl.java (core/trunk12):
>>
>>        digester.addCallMethod("faces-config/validator", 
>> "addValidator", 2);
>>        digester.addCallParam("faces-config/validator/validator-id", 0);
>>        
>> digester.addCallParam("faces-config/validator/validator-class", 1);
>>
>> So it looks like at the moment the only supported child elements of 
>> <validator> are validator-id and validator-class.
>>
>> Note that in the same method, the <converter> tag does appear to be 
>> handled correctly, with digester rules existing for nested attribute 
>> and property elements.
> I've created a JIRA issue for this:
>  https://issues.apache.org/jira/browse/MYFACES-1892
>
> However it will be a reasonable amount of work to fix this, so I would 
> suggest using a workaround rather than waiting for this to be 
> implemented..
>
> Regards,
> Simon
>
>



Re: How to set a converter default property?

Posted by "simon.kitching@chello.at" <si...@chello.at>.
simon.kitching@chello.at schrieb:
> Volker Weber schrieb:
>> [...]
>>
>> The http://java.sun.com/dtd/web-facesconfig_1_1.dtd support property
>> on validator:
>>
>> <!--
>>     The "validator" element represents a concrete Validator 
>> implementation
>>     class that should be registered under the specified validator 
>> identifier.
>>     Validator identifiers must be unique within the entire web 
>> application.
>>
>>     Nested "attribute" elements identify generic attributes that may be
>>     configured on the corresponding UIComponent in order to affect the
>>     operation of the Validator.  Nested "property" elements identify 
>> JavaBeans
>>     properties of the Validator implementation class that may be 
>> configured
>>     to affect the operation of the Validator.
>> -->
>> <!ELEMENT validator       (description*, display-name*, icon*,
>> validator-id, validator-class, attribute*, property*)>
>>   
>
> It appears that whoever implemented the faces-config parsing didn't 
> know that either. Here's code from 
> DigesterFacesConfigUnmarshallerImpl.java (core/trunk12):
>
>        digester.addCallMethod("faces-config/validator", 
> "addValidator", 2);
>        digester.addCallParam("faces-config/validator/validator-id", 0);
>        digester.addCallParam("faces-config/validator/validator-class", 
> 1);
>
> So it looks like at the moment the only supported child elements of 
> <validator> are validator-id and validator-class.
>
> Note that in the same method, the <converter> tag does appear to be 
> handled correctly, with digester rules existing for nested attribute 
> and property elements.
I've created a JIRA issue for this:
  https://issues.apache.org/jira/browse/MYFACES-1892

However it will be a reasonable amount of work to fix this, so I would 
suggest using a workaround rather than waiting for this to be implemented..

Regards,
Simon


Re: How to set a converter default property?

Posted by "simon.kitching@chello.at" <si...@chello.at>.
Volker Weber schrieb:
> Hi simon,
>
> 2008/7/10 simon.kitching@chello.at <si...@chello.at>:
>
> [...]
>   
>> The JSF standard does not support this. When defining a validator in a
>> faces-config.xml file, the only supported xml elements are validator-id and
>> validator-class.
>>     
> [...]
>
> The http://java.sun.com/dtd/web-facesconfig_1_1.dtd support property
> on validator:
>
> <!--
>     The "validator" element represents a concrete Validator implementation
>     class that should be registered under the specified validator identifier.
>     Validator identifiers must be unique within the entire web application.
>
>     Nested "attribute" elements identify generic attributes that may be
>     configured on the corresponding UIComponent in order to affect the
>     operation of the Validator.  Nested "property" elements identify JavaBeans
>     properties of the Validator implementation class that may be configured
>     to affect the operation of the Validator.
> -->
> <!ELEMENT validator       (description*, display-name*, icon*,
> validator-id, validator-class, attribute*, property*)>
>   

Ah, I didn't know that.

It appears that whoever implemented the faces-config parsing didn't know 
that either. Here's code from DigesterFacesConfigUnmarshallerImpl.java 
(core/trunk12):

        digester.addCallMethod("faces-config/validator", "addValidator", 2);
        digester.addCallParam("faces-config/validator/validator-id", 0);
        digester.addCallParam("faces-config/validator/validator-class", 1);

So it looks like at the moment the only supported child elements of 
<validator> are validator-id and validator-class.

Note that in the same method, the <converter> tag does appear to be 
handled correctly, with digester rules existing for nested attribute and 
property elements.

Just by the way, the subject on the original email was about 
"converter", but the example was about "validator". I presume the 
problem really is with a validator....

Regards,
Simon


Re: How to set a converter default property?

Posted by Volker Weber <v....@inexso.de>.
Hi simon,

2008/7/10 simon.kitching@chello.at <si...@chello.at>:

[...]
> The JSF standard does not support this. When defining a validator in a
> faces-config.xml file, the only supported xml elements are validator-id and
> validator-class.
[...]

The http://java.sun.com/dtd/web-facesconfig_1_1.dtd support property
on validator:

<!--
    The "validator" element represents a concrete Validator implementation
    class that should be registered under the specified validator identifier.
    Validator identifiers must be unique within the entire web application.

    Nested "attribute" elements identify generic attributes that may be
    configured on the corresponding UIComponent in order to affect the
    operation of the Validator.  Nested "property" elements identify JavaBeans
    properties of the Validator implementation class that may be configured
    to affect the operation of the Validator.
-->
<!ELEMENT validator       (description*, display-name*, icon*,
validator-id, validator-class, attribute*, property*)>


> Regards, Simon
>
>

Regards,
  Volker

-- 
inexso - information exchange solutions GmbH
Bismarckstraße 13 | 26122 Oldenburg
Tel.: +49 441 4082 356 |
FAX: +49 441 4082 355 | www.inexso.de

Re: How to set a converter default property?

Posted by "simon.kitching@chello.at" <si...@chello.at>.
superjoerch@gmx.de schrieb:
> Hi, i try to set a default property for a converter in this way:
> <validator>
>    <validator-id>xyValidtor</validator-name>
>    <validator-class>com.xy.XyValidator</validator-class>
>    <property>
>       <property-name>length</property-name>
>       <property-class>java.lang.Integer</property>
>       <default-value>40</default-value>
>    </property>
> </validator>
>
> I expected that setter-Methode of my Member length in the 
> XyValidator-Class will called, but only the
> default Constructor is called, so why fails my setting of a 
> Default-Property?
>
The JSF standard does not support this. When defining a validator in a 
faces-config.xml file, the only supported xml elements are validator-id 
and validator-class.

What you can do is use the validator attribute available on all input 
elements:
 <h:inputText validator="#{....}" .../>

That EL expression can then get an object from your "managed beans" 
definitions, which does support setting properties etc.

Regards, Simon