Your problem may have something to do with setting the fields = "" in reset. I would put a stdout call in reset to see when it gets called. If your forms are stored in the request (and I maybe even in the session) then you don't need to implement the reset method at all. It's really only needed to reset boolean properties.
David
From: "Thomas Miskiewicz" <[EMAIL PROTECTED]> Reply-To: "Thomas Miskiewicz" <[EMAIL PROTECTED]> To: "Struts Users Mailing List" <[EMAIL PROTECTED]> Subject: Validation Problem Date: Sun, 8 Jun 2003 22:47:25 +0200
Hi!
I now have a strange validation problem. I use this ActionForm class:
package com.mycompany;
import org.apache.struts.action.Action; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionServlet; import org.apache.struts.util.MessageResources;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession;
import java.lang.String;
public class PostTestForm extends ActionForm { private String field1 = ""; private String field2 = ""; private String field3 = "";
private void checkForEmpty(String fieldName, String fieldKey, String value, ActionErrors errors) { if (value.trim().length() == 0) { System.out.println(fieldName + value.trim().length()); ActionError error = new ActionError("error.posttest.field.null", fieldName); errors.add(fieldKey, error); } }
private void checkForLength(String fieldName, String fieldKey, String value, int maxLength, ActionErrors errors) { if (value.length() > maxLength) { ActionError error = new ActionError("error.posttest.field.length", fieldName); System.out.println(maxLength); errors.add(fieldKey, error); } }
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors();
checkForEmpty("field1", "error.field1.empty", getField1(), errors); checkForEmpty("field2", "error.field2.empty", getField2(), errors); checkForEmpty("field3", "error.field3.empty", getField3(), errors);
checkForLength("field1", "error.field1.length", getField1(), 5, errors);
checkForLength("field2", "error.field2.length", getField2(), 5, errors);
checkForLength("field3", "error.field3.length", getField3(), 5, errors);
return errors; }
public void reset(ActionMapping mapping, HttpServletRequest request) { field1 = ""; field2 = ""; field3 = ""; }
public String getField1() { return field1; }
public void setField1(String feld1) { this.field1 = field1; }
public String getField2() { return field2; }
public void setField2(String field2) { this.field2 = field2; }
public String getField3() { return field3; }
public void setField3(String field3) { this.field3 = field3; }
}
Everything works fine except the application always claims, that field1 is empty even if it's not. value.trim().length() always is = 0 with respect to the field1. The content of the HTML-Form looks like this:
<%@ page language="java" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> <%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %> <html:form action="postTest"> <table border="0" cellpadding="0" cellspacing="0" style="border-collapse:collapse" bgcolor="E7E7E7" width="100%" height="900px"> <tr> <td> <html:errors/> </td> </tr> <tr> <td> <input name="field1" type="text" size="17" maxlength="32"> </td> </tr> <tr> <td> <input name="field2" type="text" size="17" maxlength="32"> </td> </tr> <tr> <td> <input name="field3" type="text" size="17" maxlength="32"> </td> </tr> <tr> <td> <input name="submit" type="submit" value="Submit"> </td> </tr> </table> </html:form>
What's wrong???
Regards Tom
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE* http://join.msn.com/?page=features/junkmail
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]