- This topic has 1 reply, 2 voices, and was last updated 17 years, 11 months ago by Riyad Kalla.
-
AuthorPosts
-
Peter L. BergholdMemberHi folks,
I’ve been pounding my head against the desk trying to figure this one out on my own and from all the documentation I’ve read this
thing should just work but it doesn’t.Here is a JSP form:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> <%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%> <html:form action="/actions/public/system/sendEmail" method="POST" onsubmit="return validateSendEmailForm(this);"> <html:javascript formName="sendEmailForm"/> <p> Use this form to send an email. All fields are considered mandatory. Email addresses will be checked for validity. </p> <p> Please be sure to include your real name in the body of the message to avoid confusion on the part of the email recipient </p> <p style="border: 1px; color: red; "> <html:errors /> </p> <hr> <table width="100%"> <tr height="30"> <td width="30%" align="right"> From: <br> (Your email address) </td> <td> <html:text property="from_rq" size="40" maxlength="80" /> <br> <html:errors property="label.from_rq" /> </td> </tr> <tr height="30"> <td width="30%" align="right"> Subject: </td> <td> <html:text property="subject_rq" size="40" maxlength="72" /> <br> <html:errors property="subject_rq" /> </td> </tr> <tr> <td width="30%" align="right"> Message body: </td> <td> <html:textarea property="body_rq" rows="10" cols="40" /> <br> <html:errors property="body_rq" /> </td> </tr> <tr> <td colspan="2"> <table width="100%"> <tr> <td width="33%"> <html:cancel value="abort" property="action_rq" /> </td> <td width="34%"> </td> <td> <html:submit value="Send" property="action_rq"></html:submit> </td> </tr> </table> </td> </tr> </table> </html:form>
The form bean itself looks like this:
/* * * $Id: SendEmailForm.java,v 1.4 2007/01/08 15:03:16 peter Exp $ * * $Log: SendEmailForm.java,v $ * Revision 1.4 2007/01/08 15:03:16 peter * Added a crontab to the website for automation. * Updated the schema to include more information in the place table. * Added a restart script for tomcat on the site. * Added a database authentication configuration file for Perl * * Revision 1.3 2007/01/01 18:37:04 peter * The start of javadoc commentary being embedded into the various classes and modules. * * Revision 1.2 2006/12/28 03:09:14 peter * Cleaned up TODO's generated by MyEclipse's stub generation. * * * * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */ package org.bcdc.struts.form; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.validator.ValidatorForm; import org.apache.struts.action.ActionMapping; /** * MyEclipse Struts * Creation date: 12-14-2006 * * XDoclet definition: * @struts.form name="sendEmailForm" */ public class SendEmailForm extends ValidatorForm { /* * Generated fields */ /** from_rq property */ private String from_rq; /** subject_rq property */ private String subject_rq; /** body_rq property */ private String body_rq; /** action_rq **/ private String action_rq; /* * Generated Methods */ /** * @return the action_rq */ public String getAction_rq() { return action_rq; } /** * @param action_rq the action_rq to set */ public void setAction_rq(String action_rq) { this.action_rq = action_rq; } /** * Method validate * @param mapping * @param request * @return ActionErrors */ public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { // TODO: add validation of email form. // TODO: validate email address "looks like" a valid email address // TODO: validdate subject and body are not blank. ActionErrors ae = super.validate(mapping, request); System.out.println("Validation started!"); if ( (this.action_rq != null) && ("abort".equals(this.action_rq))){ return null; } return ae; } /** * Method reset * @param mapping * @param request */ public void reset(ActionMapping mapping, HttpServletRequest request) { } /** * Returns the from_rq. * @return String */ public String getFrom_rq() { return from_rq; } /** * Set the from_rq. * @param from_rq The from_rq to set */ public void setFrom_rq(String from_rq) { this.from_rq = from_rq; } /** * Returns the subject_rq. * @return String */ public String getSubject_rq() { return subject_rq; } /** * Set the subject_rq. * @param subject_rq The subject_rq to set */ public void setSubject_rq(String subject_rq) { this.subject_rq = subject_rq; } /** * Returns the body_rq. * @return String */ public String getBody_rq() { return body_rq; } /** * Set the body_rq. * @param body_rq The body_rq to set */ public void setBody_rq(String body_rq) { this.body_rq = body_rq; } }
and here is the whole mess referenced in the struts-config.xml file.
<form-bean name="sendEmailForm" type="org.bcdc.struts.form.SendEmailForm" /> <!-- other stuff between here and there --> <action attribute="sendEmailForm" input=".public.email.send" name="sendEmailForm" path="/actions/public/system/sendEmail" scope="request" validate="yes" type="org.bcdc.struts.action.SendEmailAction"> <forward name="class_detail" path="/actions/public/class/detail.do" /> <forward name="failure" path="/actions/public/sendEmail.do" /> </action> <!-- and here is the validation framework being invoked --> <message-resources parameter="org.bcdc.struts.ApplicationResources" /> <plug-in className="org.apache.struts.tiles.TilesPlugin"> <!-- Path to XML definition file --> <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" /> <!-- Set Module-awareness to true --> <set-property property="moduleAware" value="true" /> </plug-in> <plug-in className="org.apache.struts.validator.ValidatorPlugIn"> <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" /> </plug-in>
And here is the validation ruleset for this form:
<form name="sendEmailForm"> <field property="from_rq" depends="required,email"> <arg0 key="label.from_rq"/> </field> <field property="subject_rq" depends="required"> <arg0 key="label.subject_rq"/> </field> <field property="body_rq" depends="required"> <arg0 key="label.body_rq"/> </field> </form>
The ultimate goal here is to process all this server side, but I enabled the javascript stuff in an attempt to narrow down what is going
on.What I’m seeing is if I invoke the form and hit submit, instead of seeing the errors that I’d expect I’m getting a blank popup. This
would IMHO indicate that the validation framework is doing its thing, but cannot find my message library. The message library
ApplicationResources.properties is right where I’d expect it to be and here is what is in there:# Resources for parameter 'org.bcdc.struts.ApplicationResources' # Project P/www.bayshoredogclub.org label.from_rq=Your Email address label.subject_rq=Subject label.body_rq=A body of message text
The only thing I can’t seem to figure out is why it can’t find the messages…
Riyad KallaMemberMoving to OT > Soft Dev
Peter, don’t forget to double check with the Struts folks on this as well. I don’t know off hand (never used the validation framework) but I’ll ask another guy in the office that might to see if he knows. If he doesn’t (or is too busy) he many not reply though.
-
AuthorPosts