I get struts involved for localization.  I do light validation on the client
site to make sure the required values are present.  I create a stubbed
"validate()" javascript function that returns true for the stupid browsers.
So the stub looks like this:

        <SCRIPT language="JavaScript" type="text/javascript"><!--
                // This is a stub that gets overrided by validate.js.
                function validate ( form ) {
                        return true ;
                }
        //--></SCRIPT>

Right after that, I "include" my static validate.js file which contains a
few functions for doing validation:

        <SCRIPT language="JavaScript" src="validate.js"></SCRIPT>

Then at the bottom of my form, after all of the fields have been rendered, I
have a chunk of code that defines required fields and their messages:

        <SCRIPT language="JavaScript" type="text/javascript"><!--
                with ( document.survey1Form ) {
                        attendeeName.req = true ;
                        attendeeName.error = "<bean:message
key="errors.attendeeName.required" />" ;
                        position.req = false ;
                        position.error = "<%--bean:message
key="survey1.errors.position.required" /--%>" ;
                        .
                        .
                        .
                }
        //--></SCRIPT>
        
I didn't define the message for a missing "position" entry, so I just
comment out that <bean:message> in case I want one later.  The validate
function checks the required state and generates the message if needed.
Some non-required fields can make other fields required dynamically.

If you're interested, here's the contents of validate.js:

        function validate(form) {
                var valid = true ;
                with ( form ) {
                        for ( var i = 0 ; i < elements.length ; i++ ) {
                                if ( !valid ) break ;
                                if ( elements[i].req && isNull (
elements[i].value ) ) {
                                        valid = false ;
                                        elem = i ;
                                }
                        }
                        if ( !valid ) {
                                alert ( elements[elem].error ) ;
                                elements[elem].focus() ;
                        }
                }
                return valid ;
        }

        function isNull ( value ) {
                if ( value == null || value == "" || value == "null" )
return true ;
                return false ;
        }

I don't think it's good form to make .js files interpreted by Tomcat.  I
know some people add them so that they can execute JSP inside the .js files.
Me, I just set up custom field properties at the bottom of the form and send
them through a static .js which works GREAT.


Anthony

-----Original Message-----
From: Natra, Uday [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 12, 2001 8:08 AM
To: '[EMAIL PROTECTED]'
Subject: RE: Client side validation with struts


Hi Amar, Thanks for the info.

-----Original Message-----
From: Nanduri, Amarnath [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 12, 2001 10:11 AM
To: '[EMAIL PROTECTED]'
Subject: RE: Client side validation with struts


Hello Uday,

Struts is just a framework. You can include any javascript you want to. 

I use struts framework with weblogic 6.0 The best way to run these
applications is as a .war file. Throw your war files in the
bea/wlserver6.0/config/mydomain/applications  directory and weblogic will
automatically pick it up for you.

cheers,
Amar..

-----Original Message-----
From: Natra, Uday [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 12, 2001 9:30 AM
To: '[EMAIL PROTECTED]'
Subject: Client side validation with struts


Hi All,
Can any one tell me if we can use the client side java script validation
when using the struts frame work?? I mean if we are using the struts Tag
Libs in our JSP's? 
Also I want to use struts framework with WebLogic6.0. Does any one know how
struts framework go with WebLogic6.0?

I would really appreciate your feedback.

Thanks,
Uday.

Reply via email to