This week's book giveaways are in the iOS and Features new in Java 8 forums. We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line! See this thread and this one for details.
public static final java.lang.String VALIDATOR_ID = "javax.faces.Length";
I´ve tried writing my custom validator and assigning a unique id in faces-config.xml, when I try to add it to another component, I get
09:17:01,803 ERROR [MyBeanMB] Expression Error: Named Object: MyCustomValidator not found.
javax.faces.FacesException: Expression Error: Named Object: my.company.MyCustomValidator not found.
Is there any tutorial anywhere about this? How do I write validators that can be added programmatically?
I don't understand the value of dynamically adding a validator myself. Unless you're HEAVILY into dynamic View construction, it's generally easier to just define the thing statically in faces-config.xml.
Your error message would appear to indicate that things were mostly done correctly, except that you didn't include the file /WEB-INF/classes/my/company/MyCustomValidator.class in your WAR. Or its equivalent.
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Apr 15, 2008
alas I do not have an example. All I have is code in production use.
But there should be nothing complicated in using the custom validator. As I said above I use JSF 2 (MyFaces) and the above code works as is. I do NOT have anything in the config file(s) since the @FacesValidator annotation above is enough. The validate method throws javax.faces.validator.ValidatorException if the validation fails. You can google the different classes used to find what their API says about them.
I do not use the validator programmatically anywhere, I just tested it because the original poster said that his code does not work. Instead I use the validator in UI like this:
(where t: is defined as xmlns:t="http://myfaces.apache.org/tomahawk")