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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Thursday, July 10, 2008 10:57 AM
To: MyFaces Discussion
Subject: Re: How to set a converter default property?
 
[EMAIL PROTECTED] 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
 
 
  

 

Reply via email to