Using validators with Clay
I've been trying to get a custom validator working with Clay, but so far I haven't figured out how to do it. I have a class named a.b.c.IPAddressValidator that validates that a String is a valid dotted-decimal IP address, as its name implies. I've registered in my faces-config under the validator-id a.b.IPAddress. It works fine when I invoke it using JSP (i.e., using f:validator validatorId=a.b.IPAddress / nested within a h:input element). However, I have not been able to get it to work with Clay views defined either in HTML or XML. I tried this: component jsfid=my:inputIPAddress extends=t:inputText element renderId=0 jsfid=f:validator attributes set name=validatorId value=a.b.IPAddress / /attributes /element /component but I got the error Undefined component type override, presumably because the clay-config.xml that comes with Clay defines f:validator with a componentType of override. I also tried this (as XML and also in the equivalent HTML using span tags): component jsfid=my:validateIPAddress componentType=a.b.IPAddress extends=validator /component component jsfid=my:inputIPAddress extends=t:inputText element renderId=0 jsfid=my:validateIPAddress / /component but that resulted in the error Undefined component type a.b.IPAddress. I also tried swapping out my validator with the f:validateLongRange validator, with the same result. How do I get this to work? The only examples of validation in the Clay intro page show it being done with managed bean methods and the validator attribute. Rich Eggert Member of Technical Staff Proteus Technologies, LLC http://www.proteus-technologies.com
RE: Tomahawk's enabledOnUserRole attribute and Clay
Hi Which Clay tomahawk component config file are you using? Have you tried with 1.1.5-SNAPSHOT and the config file in the trunk? Hermod -Original Message- From: Richard Eggert [mailto:[EMAIL PROTECTED] Sent: Monday, March 26, 2007 11:37 PM To: user@shale.apache.org Subject: Tomahawk's enabledOnUserRole attribute and Clay Perhaps I'm overlooking something here, but from the testing I did this afternoon, it appears that the enabledOnUserRole attribute provided with most of Tomahawk's components doesn't work at all in Clay HTML templates. However, it does work properly when I use straight JSP/JSF without Clay (at least most of the time, anyway; t:commandButton seems to have issues with it). I have an HTML template that contains an element that looks something like the following: input type=checkbox jsfid=t:selectBooleanCheckbox value=#{mybean.myflag} enabledOnUserRole=myrole / When I view the page while logged in as a user that does not have the myrole role, the checkbox is still enabled, and I can use it to toggle the corresponding flag in the underlying bean. Thinking that it might be a problem with the implicit mapping of the input element, I tried changing the HTML element to just a span tag (with attributes set as above, minus the type=checkbox part), to no avail. I also tried setting enabledOnUserRole for a textarea, and it didn't work correctly there, either. visibleOnUserRole seems to work just fine, though. Any ideas on this, or should I post it to JIRA? For reference, I'm using MyFaces 1.1.4, Tomahawk 1.1.3, and Shale 1.0.4. Rich Eggert Member of Technical Staff Proteus Technologies, LLC http://www.proteus-technologies.com * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This email with attachments is solely for the use of the individual or entity to whom it is addressed. Please also be aware that the DnB NOR Group cannot accept any payment orders or other legally binding correspondence with customers as a part of an email. This email message has been virus checked by the anti virus programs used in the DnB NOR Group. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Re: Using validators with Clay
I've been trying to get a custom validator working with Clay, but so far I haven't figured out how to do it. I have a class named a.b.c.IPAddressValidator that validates that a String is a valid dotted-decimal IP address, as its name implies. I've registered in my faces-config under the validator-id a.b.IPAddress. It works fine when I invoke it using JSP (i.e., using f:validator validatorId=a.b.IPAddress / nested within a h:input element). However, I have not been able to get it to work with Clay views defined either in HTML or XML. I tried this: component jsfid=my:inputIPAddress extends=t:inputText element renderId=0 jsfid=f:validator attributes set name=validatorId value=a.b.IPAddress / /attributes /element /component There are a couple of flavors of JSF Validators. One flavor allows using a method binding expression to a managed bean callback. Components that realize the EditableValueHolder interface provide a validator attribute. Using this method, you would need the following clay XML config. component jsfid=my:inputIPAddress extends=t:inputText attributes set name=validator value=#{mybean.validateIPAddress} / /attributes /element /component Your managed bean registered as mybean would have the following callback method. public void validateIPAddress(FacesContext context, UIComponent input, Object value) { ... } but I got the error Undefined component type override, presumably because the clay-config.xml that comes with Clay defines f:validator with a componentType of override. I also tried this (as XML and also in the equivalent HTML using span tags): component jsfid=my:validateIPAddress componentType=a.b.IPAddress extends=validator /component component jsfid=my:inputIPAddress extends=t:inputText element renderId=0 jsfid=my:validateIPAddress / /component but that resulted in the error Undefined component type a.b.IPAddress. I also tried swapping out my validator with the f:validateLongRange validator, with the same result. How do I get this to work? The only examples of validation in the Clay intro page show it being done with managed bean methods and the validator attribute. There is a second way to register a validator in the clay XML config. The component and element allow a nested validator node. In this case, the jsfid needs to point to a top-level component definition that defines the validator. The componentType captures the validatorId. component jsfid=myvalidator componentType=a.b.IPAddress attributes . /attributes /component component jsfid=my:inputIPAddress extends=t:inputText ... ... validator jsfid=myvalidator attributes overrides - like an an anonymous inner class /attributes /validator /component Now, the nomenclature is getting in the way. The Clay metadata is not really JSF component specific. We use the component node to represent, components, validators, converters and listeners. At one time it was called displayElement. There is yet another way to define a validator. If you are using the html namespaces, you would use JSP syntax. span jsfid=void xmlns:f=http://java.sun.com/jsf/core; xmlns:t=http://myfaces.apache.org/tomahawk; t:inputText ... f:validator validatorId=a.b.IPAddress/ /t:inputText /span Or, yet another... span jsfid=void xmlns:clay=http://shale.apache.org/xml/clay; clay:element jsfid=t:inputText clay:attributes clay:set/ /clay:attributes clay:validator jsfid=a.b.IPAddress/ /clay:element /span Rich Eggert Member of Technical Staff Proteus Technologies, LLC http://www.proteus-technologies.com Gary