It's not a secret anymore!
The moose likes Struts and the fly likes Client-side validation using ValidatorActionForm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Client-side validation using ValidatorActionForm" Watch "Client-side validation using ValidatorActionForm" New topic

Client-side validation using ValidatorActionForm

Cliff Edwards

Joined: Mar 22, 2004
Posts: 16
Hello All,

This question refers to Struts 1.2.7.

I'm trying to use the feature of the validator that enables you to specify an action to validate instead of a form. (I'm using a form class that extends ValidatorActionForm.) This form is used by several actions, each in their own way.

The problem is-- actions begin with a slash. So what do you code in the onsubmit parameter in the JSP? The spec says to put "validate" in front of the form/action name, but the action name begins with a slash.

For example, my action is /Login. That would make the onsubmit look like this: onsubmit="return validate/Login(this);". This won't work.

How do you handle this? -- or can you refer me to an article that address this situation?

Cliff Edwards

Joined: Mar 22, 2004
Posts: 16
Since posting my question today, I've learned that client-side validation works OK by specifying: onsubmit="return validateUserForm(this);" within the form definition in the calling JSP. I can't find specific documentation about this, but it seems to work.

But I get the following javascript error each time. However, It doesn't seem to affect proper execution; everything seems to work OK.

Error: [Exception... "'Permission denied to get property XULElement.selectedIndex' when calling method: [nsIAutoCompletePopup::selectedIndex]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "JS frame :: http://localhost:9080/xxxxx/login.jsp :: validateRequired :: line 286" data: no]
Source File: http://localhost:9080/xxxxxx/login.jsp
Line: 286

.... Sure would like to see a detailed article describing the use of the Struts validator using multiple actions with a common form.

Cliff Edwards

Joined: Mar 22, 2004
Posts: 16
To sum up: So, when using the validator to check multiple actions that share a common form bean, you code your form class to extend ValidatorActionForm, and specify actions instead of forms everywhere EXCEPT within the onsubmit Javascript command. Within the onsubmit command, you specify the form name, as it is in the struts-config file.

I agree. Here's the link:
subject: Client-side validation using ValidatorActionForm
jQuery in Action, 3rd edition