Results 1 to 4 of 4
  1. #1
    Peter is offline Senior Member
    Join Date
    Jun 2007
    Posts
    119
    Rep Power
    0

    Default DynaValidatorForm isn't working

    Hi,

    When I enter an invalid login the page doesn't display error messages.
    These are my pages.



    LOGIN.JSP

    Java Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <&#37;@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
    <html:html>
    <head>
    
    <%@ page
    language="java"
    contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"
    %>
    <META name="GENERATOR" content="IBM Software Development Platform">
    <meta http-equiv="Content-Type" content="text/html;">
    <title>Untitled</title>
    
    
    <style>
    TD{
    font-family:verdana,arial;
    color:black;
    font-size:8pt;
    
    }
    .news{
    font-family:arial;
    }
    .bot{
    color:black;
    text-decoration:none;
    font-size:7pt;
    font-family:Verdana;
    font-weight:bold;
    
    }
    .copy{
    font-size:7pt;
    color:black;
    }
    </style>
    </head>
    
    <body>
    
    <html:errors/>
    
    <html:form action="/submitLogin" >
    
    <table border="0" cellpadding="0" cellspacing="0" width="159">
    
    
    <tr>
    <td valign="top" class="news"><b>UserName: </b></td>
    <td> <html:text property="userName" size="11" />
    
    
    </td>
    </tr>
    
    <tr>
    
    
    <td valign="top" class="news"><b>PassWord: </b></td>
    <td> <html:text property="passWord" size="11" />
    </td>
    
    </tr>
    
    <tr>
    
    <td valign="top"class="news"><INPUT type="submit" value="Logon"></td>
    
    </tr>
    
    </table>
    </html:form>
    
    </BODY>
    </html:html>
    STRUTS_CONFIG.xml
    Java Code:
    
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts
    
    Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
    <struts-config>
    
    <!-- Data Sources -->
    <data-sources>
    </data-sources>
    
    <!-- Form Beans -->
    <form-beans>
    <form-bean name="LoginForm"
    
    type="org.apache.struts.validator.DynaValidatorForm">
    
    <!-- Dynamic properties of the Login Form -->
    <form-property name="userName" type="java.lang.String" />
    <form-property name="passWord" type="java.lang.String" />
    
    </form-bean>
    </form-beans>
    
    <!-- Global Exceptions -->
    <global-exceptions>
    </global-exceptions>
    
    <!-- Global Forwards -->
    <global-forwards>
    </global-forwards>
    
    <!-- Action Mappings -->
    <action-mappings>
    <action path="/myPath" forward="/main.jsp" />
    <action path="/submitLogin" scope="request"
    
    type="com.poshWebApp.actions.LoginAction" name="LoginForm" validate="false"
    
    input="/web/pages/login/login.jsp">
    <forward name="success" path="/main.jsp" />
    </action>
    </action-mappings>
    
    <!-- Message Resources -->
    <message-resources parameter="pbwebapp.resources.ApplicationResources"/>
    
    <!-- Validator Plugin -->
    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,
    
    /WEB-INF/validation.xml" />
    </plug-in>
    
    </struts-config>

    LOGINACTION.java
    Java Code:
    package com.poshWebApp.actions;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.validator.DynaValidatorForm;
    
    /**
    * Form bean for a Struts application.
    * Users may access 2 fields on this form:
    * <ul>
    * <li>passWord - [your comment here]
    * <li>userName - [your comment here]
    * </ul>
    * @version 1.0
    * @author
    */
    public class LoginAction extends Action {
    
    public ActionForward execute(ActionMapping mapping,
    ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws Exception {
    
    DynaValidatorForm dynaform = (DynaValidatorForm) form;
    
    request.setAttribute(mapping.getAttribute(), dynaform);
    
    System.out.println("Forwarding - SUCCESS page");
    
    return mapping.findForward("success");
    }
    
    
    }
    Validation.xml
    Java Code:
    <formset>
    <form name="LoginForm">
    <field property="userName" depends="required">
    <arg0 key="prompt.username" />
    </field>
    <field property="passWord" depends="required, minlength,
    
    maxlength">
    <arg0 key="prompt.password" />
    <arg1 key="${var:minlength}" name="minlength"
    
    resource="false" />
    <arg2 key="${var:maxlength}" name="maxlength"
    
    resource="false" />
    
    
    <var>
    <var-name>minlength</var-name>
    <var-value>6</var-value>
    </var>
    <var>
    <var-name>maxlength</var-name>
    <var-value>12</var-value>
    </var>
    </field>
    </form>
    </formset>
    What's the problem?

  2. #2
    Heather is offline Senior Member
    Join Date
    Jun 2007
    Posts
    164
    Rep Power
    8

    Default

    set validate="true" instead of validate="false"

  3. #3
    Jack is offline Senior Member
    Join Date
    Jun 2007
    Posts
    130
    Rep Power
    0

    Default

    try once :remove doctype in validation.xml

  4. #4
    JavaEmpires is offline Member
    Join Date
    Dec 2007
    Posts
    19
    Rep Power
    0

    Default


    Try this----

    first of all make validate=true
    write onsumit=" return validateLoginForm(this);" in your form tag
    write <html:javascript formName="LoginForm" /> in your jsp before </html:form> tag

    Having include above things, I think your form should work..


Similar Threads

  1. keyListener isn't working for me
    By lost_in_java in forum AWT / Swing
    Replies: 7
    Last Post: 12-05-2008, 04:24 AM
  2. Exceptions related to DynaValidatorForm
    By rameshraj in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 12-27-2007, 11:44 AM
  3. Exceptions related to DynaValidatorForm
    By rameshraj in forum Java Servlet
    Replies: 0
    Last Post: 12-26-2007, 10:43 AM
  4. working with servlets
    By Freddie in forum Java Servlet
    Replies: 2
    Last Post: 05-15-2007, 05:50 PM
  5. Working With ANT
    By JavaForums in forum Eclipse
    Replies: 0
    Last Post: 04-26-2007, 08:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •