You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Peter L. Berghold" <Pe...@berghold.net> on 2007/01/06 00:29:53 UTC

Struts validation (still) (again!) (ARRGH!)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

OK,

I've been hacking around some more on this validation stuff and while
some of the suggestions I've been given have been a HUGE help I'm still
stuck.

Re-distilling the problem a bit I think I may have stumbled on something
but I'm not quite sure what to make of it.

Here are the ApplicationResources I have defined:

# 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

Fairly simple... or so I'd think...

Here is where the resource file is referenced in the struts-config.xml
file.

<message-resources parameter="org.bcdc.struts.ApplicationResources" />

so far so good, I look in the WEB-INF/classes/... tree and find the file
where I think it should belong under
org/bcdc/struts/ApplicationResources.properties

Awwright. Now I look at my .jsp form and here it is in its entirety.

<%@ 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%">
							&nbsp;
						</td>
						<td>
							<html:submit value="Send" property="action_rq"></html:submit>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>

</html:form>

Here's the input form being described in struts-config.xml

<form-bean name="sendEmailForm"
			type="org.bcdc.struts.form.SendEmailForm" />
and the associated action
<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>

Here is the validation formset entry 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>


Now... in the end I don't want to use Javascript for my validation, I'd
like to be able to do all this server side.  However I used the
JavaScript stuff just to figure out what is going on.

When the form is submitted completely blank (which should generate an
error.. and it does) I get a popup with NOTHING IN IT but an yellow
exclamation mark.

The conclusion I'm drawing is that the validation framework is for some
unknown reason not finding the resource file.  Was there something the
the validation.xml file that was supposed to point to this file or
should it have picked it up on its own?

Someone suggested I use a set of tags to try in invoke the message
"manually" but that crashed the app so I'm guessing I'm on the right
track...


- --
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Peter L. Berghold                                     Peter@Berghold.Net
"Those who fail to learn from history are condemned to repeat it."
AIM: redcowdawg        Yahoo IM: blue_cowdawg              ICQ: 11455958
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Red Hat - http://enigmail.mozdev.org

iD8DBQFFnt9wUM9/01RIhaARAifqAKCItwt9x6dhOoouKl1DJg/LQkmrKACgyS8l
wQ2HZGnpgzlGXqTSwOHycWk=
=dICY
-----END PGP SIGNATURE-----


Re: Struts validation (still) (again!) (ARRGH!)

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Peter,

Peter L. Berghold wrote:
> <message-resources parameter="org.bcdc.struts.ApplicationResources" />

Oh, and make sure that your file gets put into WEB-INF/classes (or some
subdirectory thereof), or by some other means into the classpath. I
don't think it'll work if it's just in WEB-INF.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFnu069CaO5/Lv0PARAkrgAJ9O71Et/PO4NJ/dr6Ar0OnQfR0XIACghTW8
/4zXueG/bovak9huBv3v0Pk=
=nrkH
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts validation (still) (again!) (ARRGH!)

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Peter,

Peter L. Berghold wrote:
> <message-resources parameter="org.bcdc.struts.ApplicationResources" />

Hmm... I don't usually put stuff like this in "packages" but you might
want to use slashes instead of dots. Give it a try and see...

> When the form is submitted completely blank (which should generate an
> error.. and it does) I get a popup with NOTHING IN IT but an yellow
> exclamation mark.

Try adding the 'null="false"' attribute to your <message-resources>
element: that should then give you error messages in the form
???label.body_rq??? so at least you can verify that the correct message
key is being used (you get "???" + the key + "???", along with some
locale information if that's being used).

> The conclusion I'm drawing is that the validation framework is for some
> unknown reason not finding the resource file.  Was there something the
> the validation.xml file that was supposed to point to this file or
> should it have picked it up on its own?

Your validation config should use the existing application resource
files correctly. I'm assuming you aren't using an ancient version of
anything, are you?

Also, you only have one resource bundle, right? If you have more than
one, I think you have to name them using the "key" attribute of the
<message-resources> element. For instance, I have 6 bundles, one of
which is called ApplicationResources.properties and has no "key". This
contains generic stuff. At some point, the single bundle was getting out
of control, so I split it up and have 6, now. Anyhow, when I did that, I
had to add a "bundle" attribute to all of the validator fields that used
message bundle keys (and whose messages were not in the generic bundle).
Just a note for future use.

Hope that helps,
- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFnuzo9CaO5/Lv0PARAoc3AKCq5yJ1X98ICXJKwsWoDPV9a+l1IwCeN/mv
Ek5ZlzfFVzw5fRXPcPKnTS4=
=o36v
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org