• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 824
  • Last Modified:

struts client side validation does not work

Hi,

I am trying to do 'struts client side validation ' example from link

http://www.vaannila.com/struts/struts-example/struts-client-side-java-script-validation-example-1.html.

 My login is going successful even if i do not give paasowrd or give password less than 6 characters(which supposed to give client side validation error in this case instead). Problem seems to be in jsp files like login.jsp etc struts htm:form, html:text, html:password, html:submit etc tags are not recognized properly. I followed same steps as mentioned in the link. But still there are these issues. How can i resolve this issues so that i can see proper client side validation error messages saying password cannot be less than 6 character, null etc whenever i put password less than 6 or null.

 Any ideas, suggestions, resources, links, sample code highly appreciated. Thanks in advance
validationLogin.JPG
validationStrutsConfig.JPG
0
gudii9
Asked:
gudii9
  • 4
2 Solutions
 
Gurvinder Pal SinghCommented:
Can you show source code of loginForm, in the validation.xml?

You can also use the following links for reference
http://www.roseindia.net/struts/struts_validator_framework.shtml
http://struts.apache.org/1.3.8/faqs/validator.html

0
 
deeppraCommented:
paste the whole stack trace instead of posting the image, and also make sure you are including the correct taglib. See whether you have the tld file inside your /web-inf/ dir.
0
 
gudii9Author Commented:
Hi,

Console message look like

[12/28/09 11:59:12:250 CST] 00000028 Validator     E org.apache.commons.logging.impl.Jdk14Logger error reflection: org.apache.struts.validator.FieldChecks.validateRequired(java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionMessages, org.apache.commons.validator.Validator, javax.servlet.http.HttpServletRequest)
                                 java.lang.NoSuchMethodException: org.apache.struts.validator.FieldChecks.validateRequired(java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionMessages, org.apache.commons.validator.Validator, javax.servlet.http.HttpServletRequest)
      at java.lang.Class.throwNoSuchMethodException(Class.java:275)
      at java.lang.Class.getMethod(Class.java:780)
      at org.apache.commons.validator.Validator.validateFieldForRule(Validator.java:401)
      at org.apache.commons.validator.Validator.validateField(Validator.java:544)
      at org.apache.commons.validator.Validator.validate(Validator.java:582)
      at org.apache.struts.validator.DynaValidatorForm.validate(DynaValidatorForm.java:151)
      at org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:942)
      at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255)
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
      at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:966)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
      at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:463)
      at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:92)
      at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:744)
      at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1433)
      at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:93)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:465)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:394)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:274)
      at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
      at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
      at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:152)
      at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:213)
      at com.ibm.io.async.AbstractAsyncFuture.fireCompletionActions(AbstractAsyncFuture.java:195)
      at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
      at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:194)
      at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:741)
      at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:863)
      at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1510)

[12/28/09 11:59:12:281 CST] 00000028 Validator     E org.apache.commons.logging.impl.Jdk14Logger error reflection: org.apache.struts.validator.FieldChecks.validateRequired(java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionMessages, org.apache.commons.validator.Validator, javax.servlet.http.HttpServletRequest)
                                 java.lang.NoSuchMethodException: org.apache.struts.validator.FieldChecks.validateRequired(java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionMessages, org.apache.commons.validator.Validator, javax.servlet.http.HttpServletRequest)
      at java.lang.Class.throwNoSuchMethodException(Class.java:275)
      at java.lang.Class.getMethod(Class.java:780)
      at org.apache.commons.validator.Validator.validateFieldForRule(Validator.java:401)
      at org.apache.commons.validator.Validator.validateField(Validator.java:544)
      at org.apache.commons.validator.Validator.validate(Validator.java:582)
      at org.apache.struts.validator.DynaValidatorForm.validate(DynaValidatorForm.java:151)
      at org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:942)
      at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255)
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
      at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:966)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
      at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:463)
      at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:92)
      at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:744)
      at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1433)
      at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:93)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:465)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:394)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:274)
      at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
      at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
      at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:152)
      at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:213)
      at com.ibm.io.async.AbstractAsyncFuture.fireCompletionActions(AbstractAsyncFuture.java:195)
      at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
      at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:194)
      at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:741)
      at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:863)
      at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1510)

[12/28/09 11:59:12:359 CST] 00000028 ServletWrappe I   SRVE0242I: [Struts1ClientJavaScriptvalidationVanillaEAR] [/Struts1ClientJavaScriptvalidationVanilla] [/success.jsp]: Initialization successful.




validation.xml looks like

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE form-validation PUBLIC
          "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN"
          "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">

<form-validation>

<!--
     This is a minimal Validator form file with a couple of examples.
-->

    <global>

        <!-- An example global constant
        <constant>
            <constant-name>postalCode</constant-name>
            <constant-value>^\d{5}\d*$</constant-value>
        </constant>
        end example-->

    </global>

    <formset>

         <form name="LoginForm">
            <field
                property="userName"
                depends="required">
                    <arg key="LoginForm.userName"/>
            </field>
            <field
                property="password"
                depends="required,minlength">
                    <arg0 key="LoginForm.password"/>
                    <arg1 key="${var:minlength}" name="minlength" resource="false"/>
                    <var>
                        <var-name>minlength</var-name>
                        <var-value>6</var-value>
                    </var>
            </field>
        </form>

        <!-- An example form -->
        <form name="logonForm">
            <field
                property="username"
                depends="required">
                    <arg key="logonForm.username"/>
            </field>
            <field
                property="password"
                depends="required,mask">
                    <arg key="logonForm.password"/>
                    <var>
                        <var-name>mask</var-name>
                        <var-value>^[0-9a-zA-Z]*$</var-value>
                    </var>
            </field>
        </form>

    </formset>

    <!-- An example formset for another locale -->
    <formset language="fr">

        <constant>
            <constant-name>postalCode</constant-name>
            <constant-value>^[0-9a-zA-Z]*$</constant-value>
        </constant>

        <!-- An example form -->
        <form name="logonForm">
            <field
                property="username"
                depends="required">
                    <arg key="logonForm.username"/>
            </field>
            <field
                property="password"
                depends="required,mask">
                    <arg key="logonForm.password"/>
                    <var>
                        <var-name>mask</var-name>
                        <var-value>^[0-9a-zA-Z]*$</var-value>
                    </var>
            </field>
        </form>

   </formset>

</form-validation>



please advise
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gudii9Author Commented:
Hi,

My web.xml looks like this

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
            <param-name>config</param-name>
            <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
        <init-param>
            <param-name>debug</param-name>
            <param-value>2</param-value>
        </init-param>
        <init-param>
            <param-name>detail</param-name>
            <param-value>2</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
        </servlet>
    <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>login.jsp</welcome-file>
        </welcome-file-list>
    <jsp-config>
        <taglib>
            <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
            <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
            <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
            <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>
            <taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
            <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
        </taglib>
        </jsp-config>
    </web-app>



login.jsp looks like

<%--
    Document   : login
    Created on : Dec 15, 2008, 4:03:55 AM
    Author     : eswar@vaannila.com
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JS Validation</title>
    </head>
    <body>
        <html:form action="/Login" onsubmit="validateLoginForm(this);">
            <html:javascript formName="LoginForm" />
            User Name : <html:text name="LoginForm" property="userName" /> <br>
            Password  : <html:password name="LoginForm" property="password" /> <br>
            <html:submit value="Login" />
        </html:form>
    </body>
</html>



I also have all tlds within web-ing
tlds.JPG
0
 
gudii9Author Commented:
Hi,

Looks like few jars were not copied properly to web-inf/lib. After putting them everything working fine
0
 
gudii9Author Commented:
thank you very much
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now