>From: "Ian.Priest" <[EMAIL PROTECTED]> 

> I've hit a problem trying to set up a validator on an input text field. 
> Here's the HTML... 
> 
> 
>
><div class="content"
>      xmlns:t="http://myfaces.apache.org/tomahawk"; 
>      xmlns:h="http://java.sun.com/jsf/html";
>      xmlns:f="http://java.sun.com/jsf/core";>
>
> 
> 
> ... 
> 
>
> <h:inputText styleClass="x-large" size="20" maxlength="20"
>                  value="[EMAIL PROTECTED]"
>                  id="username"
>                  validator="[EMAIL PROTECTED]" 
>                  required="true" >
> 
>   <f:validator validatorId="com.scn.Regex" suppliedRegex="[A-Za-z0-9]*"
>        errorMessage="#{messages['customer.username_invalid_chars']}" />
></h:inputText>
>
>
> 
> And here's the error message.... 
> 
>

There are a couple issues here.  The first issue is that the mapping logic is 
only looking for a "validator" and not a "f:validator".  This one is a bug.  
Please log a JIRA ticket if you get a chance.

However, you will still need to define this validator as a clay XML component 
definition because it is statefull and has attributes.  The HTML mapping will 
only push property values on to a "component" that has attributes defined in 
the clay config.  All other HTML attributes are treated as symbols.

Consider the following:


Clay XML Config:
<component jsfid="scn:regex" componentType="com.scn.Regex">
   <attributes>
      <set name="suppliedRegex" bindingType="Early" />
      <set name="errorMessage"  bindingType="Early"/>
   </attributes>
</component>



HTML Template:

<div class="content"
      xmlns:t="http://myfaces.apache.org/tomahawk"; 
      xmlns:h="http://java.sun.com/jsf/html";
      xmlns:f="http://java.sun.com/jsf/core";>

<h:inputText styleClass="x-large" size="20" maxlength="20"
                  value="[EMAIL PROTECTED]"
                  id="username"
                  validator="[EMAIL PROTECTED]" 
                  required="true" >
 
   <f:validator jsfid="scn:regex" suppliedRegex="[A-Za-z0-9]*"
      errorMessage="#{messages['customer.username_invalid_chars']}" />
</h:inputText>

</div>

-- or,  if you are into verbose markup --

<div class="content"
      xmlns:clay="http://shale.apache.org/xml/clay";>

<clay:element jsfid=":inputText>
  <clay:attributes>
     <clay:set name="styleClass" value="x-large"/> 
     <clay:set name="size" value="20" />
     <clay:set name="maxlength" value="20"/>
     <clay:set name="value" value="[EMAIL PROTECTED]"/>
     <clay:set name="id" value="username"/>
     <clay:set name="validator" value="[EMAIL PROTECTED]" />
     <clay:set name="required" value="true" />
  </clay:attributes>
   
  <clay:validator jsfid="scn:regex">
     <clay:attributes>
        <clay:set name="suppliedRegex" value="[A-Za-z0-9]*" />
        <clay:set name="errorMessage" 
value="#{messages['customer.username_invalid_chars']}" />
    </clay:attributes>
  </clay:validator>
</clay:element>

</div>



 
> 
> 2007-06-28 17:22:52,574 [http-8443-Processor23] ERROR 
> [org.apache.shale.clay.component.chain.CreateComponentCommand] Cannot 
> create Component renderId="997" jsfid="f:validator" 
> componentType="override" extends="f:validator" allowBody="null" 
> facetName="null" 
> 
> javax.faces.FacesException: Undefined component type override 
> 
> ... 
> 
> 
> 
> It works fine as-is, defined in component form like this... 
> 
> 
> 
> 
> 
> 
> 
> > value="[EMAIL PROTECTED]@validateMethod}" /> 
> 
> 
> 
> 
> 
> > extends="widgetsValidatedInputText"> 
> 
> 
> 
> 
> 
> 
> 
> > /> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> But unfortunately I have a requirement to strip out the component layer 
> and use the JSF tags direct so I can't leave it as-is. (And I also 
> realise it's slightly unusual to have two validators). 
> 
> 
> 
> Cheers, 
> 
> Ian. 
> 
> 
> 
> 
> 
> 

Reply via email to