On 12/22/05, JEEVANATHAM P.     /BPCRP/INFOTECH/VASHI
<[EMAIL PROTECTED]> wrote:

> Please let me know about how can we do server side validation in shale. Like
> user validation,
>
> when user enters some value that time we need to check with database whether
> that is correct one or not.

This is an interesting question because I have a custom validator in a
Struts app that does exactly that.  Here's what I came up with, though
I would advise waiting for Craig to comment on whether he intended for
this to happen. :)

I added another <validator> to validator-rules.xml:

       <validator name="lenientDate"
             classname="net.wsmoak.acctmtce.ValidationUtil"
             method="isDate"
             methodParams="java.lang.String"
             msg="errors.lenientDate">
       </validator>

The ValidationUtil.isDate method takes a String and returns true/false
(boolean).

Left to its own devices, oas.validatorCommonsValidator uses the
(localized) messages.properties file in org.apache.struts.validator
(inside shale-core.jar).  Since I know the Servlet spec requires that
things in WEB-INF/classes be loaded before things in WEB-INF/lib, I
extracted the messages.properties file from shale-core.jar, to
WEB-INF/classes/org/apache/shale/validator/, and added my new message
to it.

In the JSP:

    <h:outputText value="#{messages['prompt.effectiveDate']}"/>
    <h:inputText     id="effectiveDate"
                  value="#{effectiveDate}">
          <s:commonsValidator
                   type="lenientDate"
                 server="true"
                 client="false"/>
    </h:inputText>
    <h:message           for="effectiveDate" styleClass="errors"/>

At least for simple validations, it appears to work fine.  It has
advantages over all of  the 'pure JSF' methods that I investigated-- I
certainly don't want to write a custom Validator, and even a simple
method binding in the 'validator' attribute of a component means
you're responsible for formatting the error message.  But if you need
more/different parameters than the ones <s:commonsValidator> provides,
then I do think you'd need to write your own custom JSF Validator and
tag, or possibly extend the ones in Shale.

I'm going to open a couple of enhancement tickets for things like
including validator-rules.xml in shale-core.jar so that you don't have
to find and include a copy in your webapp to use the provided
validators, and making the the name and location of both the messages
and the validation rules file(s) configurable.  Other ideas and
suggestions are welcome!

HTH,
--
Wendy
http://wiki.wsmoak.net/cgi-bin/wiki.pl?ShaleValidator

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to