struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "MaFai" <zh...@hkbn.com.hk>
Subject Validator Still confusing me
Date Mon, 30 Jun 2003 11:33:44 GMT
Hello, struts-user,

Attemptto implement the simplest validator in 3 days,I nearly exhuasted.
Pls give me a hand.

My strut project as the following:

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

<form-validation>

   <global>
      <validator name="required"
            classname="org.apache.struts.validator.FieldChecks"
               method="validateRequired"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionErrors,
                       javax.servlet.http.HttpServletRequest"
                  msg="errors.required">
      </validator>
   </global>

</form-validation>

validationi.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>

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

<form-validation>
   <global>
   </global>
   <formset>
      <form    name="lookupForm">
         <field    property="symbol"
         	   depends="required,mask,minlength">
         	     <arg0 key="lookupForm.symbol"/>
                     <var>
                       <var-name>mask</var-name>
                       <var-value>^\w+$</var-value>
                     </var>
                     <var>
                       <var-name>minlength</var-name>
                       <var-value>5</var-value>
                     </var>
         </field>     
	</form>
   </formset>
</form-validation>


Struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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>
		
	<form-beans>
			<form-bean name="lookupForm" type="mystrut.LookupForm"/>
	</form-beans>
	<action-mappings>
		
			<action path="/Lookup"
				type="mystrut.LookupAction"
				name="lookupForm"
				scope="request"
				validate="true"
				input="/index.jsp">
			<forward name="success" path="/quote.jsp"/>
			<forward name="failure" path="/index.jsp"/>
		</action>
	</action-mappings>
  <message-resources
    parameter="mystrut.ApplicationResources"/>

  <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>	

index.jsp
<%@ page language="java" %>
<%@ taglib uri = "/WEB-INF/lib/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<logic:messagesPresent>
	<bean:write name="error"/>
</logic:messagesPresent>
<html:form action="Lookup" name="lookupForm" type="mystrut.LookupForm">
	<table>
		<tr>
			<td>
				Symbol
			</td>
			<td>
				<html:text property="symbol" />
			</td>
			<td>
				<html:submit />
			</td>
		</tr>		
	</table>
</html:form>




web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
	<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>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>action</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>
	<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>
</web-app>

LookupForm
package mystrut;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;
import org.apache.struts.validator.ValidatorForm;
import org.apache.struts.validator.FieldChecks;
public class LookupForm extends ValidatorForm
{
	private String symbol = null;
	public String getSymbol()
	{
		return symbol;
	}
	public void  setSymbol(String symbol)
	{
		this.symbol = symbol;
	}
	public void reset(ActionMapping mapping,HttpServletRequest request)
	{
		this.symbol = null;
	}
}

LookupAction
package mystrut;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
public class LookupAction extends Action
{
	protected Double getQuote(String symbol)
	{
			return new Double(3.01);
	}
	public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse
response)
		throws IOException,ServletException
	{
		Double price = null;
		String target = new String("success");
		if(form != null)
		{
			LookupForm lookupForm = (LookupForm)form;
			String symbol = lookupForm.getSymbol();
			price = getQuote(symbol);
		}


		if( price == null)
		{
			target = new String("failure");
		}
		else
		{
			request.setAttribute("PRICE",price);
		}
		return (mapping.findForward(target));
	}

	public static void main(String[] args)
	{
		System.out.println("Hello World!");
	}
}


No matter what I type in the filed of index.jsp,there is no error message return and always
not validate the field.
There is also no error log or error message in tomcat's log.
I have read different manuals about validate,and review my flow again and again.Util now,I
still could not found my fault.
It really beat me.

Any idea would be appreciated.



Best regards. 

MaFai
zh-ma@hkbn.com.hk
2003-06-30


Mime
View raw message