RE: Validator FrameWork

2006-12-07 Thread O'Shea, Sean
Use the validWhen validator for the password and the passwordCheck
fields: http://struts.apache.org/1.2.x/userGuide/dev_validator.html
You'll need to add the passwordCheck field to your registerForm.

I've found these links useful when investigating commons-validator:

*   commons validator examples:
http://wiki.apache.org/jakarta-commons/ValidatorExamples
*   Struts and commons-validator tutorial:
http://struts.apache.org/1.1/userGuide/dev_validator.html
*   Struts validation framework tutorial:
http://www.onjava.com/pub/a/onjava/2002/12/11/jakartastruts.html
*   Oracle article on Struts validation framework:
http://www.oracle.com/technology/oramag/oracle/04-jan/o14dev_struts.html
*   Very simple Struts validation example:
http://wiki.apache.org/struts/StrutsBeginnerValidatorFramework?highlight
=%28validator%29
*   Helpful Struts validation site:
http://www.niallp.pwp.blueyonder.co.uk/
*   Validation of lists:
http://wiki.apache.org/struts/StrutsCatalogLazyList
*   Useful validator tip for extends:
http://wiki.apache.org/jakarta-commons/ValidatorVersion120

Sean

-Original Message-
From: Thomas Thomas [mailto:[EMAIL PROTECTED] 
Sent: Thursday, December 07, 2006 3:05 PM
To: Struts Users Mailing List
Subject: Validator FrameWork

 Hi,
I'm using Validator Framework with Struts,
Here I want to validate a registration form.

I want to add a field property passwordCheck, (the user needs to enters
his
password twice : the first password will be in property password, the
second
in passwordCheck)
I want to check if value of password and passwordCheck are the same.
How can I do this ?
Thank u.
Here is my code from now on without the field property passwordCheck :

 formset
  form name=registerForm
   field property=login depends=required
  arg key=required.login/
  /field
  field property=password depends=required
  arg key=required.password/
  /field
  field property=eMail depends=required
  arg key=required.eMail/
  /field
  field property=birthYear depends=required
  arg key=invalid.dateOfBirth/
  /field
  field property=gender depends=required
  arg key=invalid.gender/
  /field
  /form
 /formset


(In addition to that, I have a lot of difficulties to find information
myself about validator framework, do u have any link for a full
documentation ?)


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Validate length of array

2006-12-05 Thread O'Shea, Sean
Hi all,

I'm using struts 1.2.7 with commons-validator 1.1.4

I've this DynaValidatorActionForm which has the following properties:

form-bean name=TOAForm dynamic=true
type=org.apache.struts.validator.DynaValidatorActionForm
form-property name=fundsTransfer type=com.myform.Transfer[]
size=3 /
form-property name=id type=java.lang.String /
/form-bean

I have the corresponding rules defined:

form name=/brokeragePartialTransfer
field property=fundName  indexedListProperty =fundsTransfer
depends=required,minlength,maxlength 
arg key=TOAForm.fundName position=0/
arg1 name=minlength key=${var:minlength} resource=false
position=1/
arg2 name=maxlength key=${var:maxlength} resource=false
position=1/
var
var-nameminlength/var-name
var-value3/var-value
/var
var
   var-namemaxlength/var-name
   var-value20/var-value
/var
/field
field property=noOfShares indexedListProperty
=fundsTransfer depends=required,minlength,maxlength

arg key=TOAForm.noOfShares /
arg name=minlength key=${var:minlength} resource=false
position=1/
arg name=maxlength key=${var:maxlength} resource=false
position=1/  
var
   var-nameminlength/var-name
   var-value3/var-value
/var
var
   var-namemaxlength/var-name
   var-value20/var-value
/var
/field

/form

From my understanding, these validations will validate the noOfShares
and fundName properties which are part of the com.myform.Transfer POJO.
In addition to these individual validations I also need to ensure that
the user has entered at least one com.myform.Transfer bean. ie. I need
to make sure that the fundsTransfer array has a size of greater than 1.
Is there a way to include this type of validation in XML format?

Hope someone has come across this problem before and can offer some help

Thanks

Sean O Shea


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Struts 1.3.5 build

2006-10-27 Thread O'Shea, Sean
Hi there,

I'm investigating into how I can migrate from struts 1.2.9 to struts
1.3.5. I've checked out the release notes at
http://struts.apache.org/1.x/userGuide/release-notes.html and I notice
that the entire struts distribution is now built using Maven 2.

I was previously using ANT to build struts using the sample build.xml
which comes packaged with the 1.2.9 distribution. I added some of my own
pre-processing steps in the 1.2.9 the build.xml which I need to
replicate if I want to move to struts 1.3.5.

Is it possible to build the struts core package using ANT? I'd prefer to
stay with ANT rather than introduce Maven 2 into my build.

Any help is greatly appreciated

Thanks

Sean

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Resource bundles and Struts taglibs

2006-08-23 Thread O'Shea, Sean
Hi all,

I'm using struts 1.2.9 and I'm having some trouble with resource
bundles. My JSP looks like this:

%@ include file=../taglibs.jsp %
logic:messagesPresent
h3 class=redbean:message key=errors.header
bundle=otherBundle//h3
bean:message key=errors.subheader bundle=otherBundle /
ul
html:messages id=error
libean:write name=error
bundle=otherBundle //li
/html:messages
/ul
hr
/logic:messagesPresent

I'm plugging my resources into my struts-config.xml like this:

message-resources parameter=resources.ApplicationResources
null=false/
message-resources key=otherBundle parameter=resources.OtherBundle
null=false/

Both the bean:message messages get outputted as expected. This means
that the otherBundle resources are definitely registered with the
application.

However, the bean:write message does not get outputted as expected - I
get a ??? errors.foo.bar ??? message on the JSP

I've debugged the tag libraries and I think both bean:message and
bean:write call the org.apache.struts.taglib.TagUtils.message method
detailed below:

public String message(
PageContext pageContext,
String bundle,
String locale,
String key,
Object args[])
throws JspException {

MessageResources resources =
retrieveMessageResources(pageContext, bundle, false);

Locale userLocale = getUserLocale(pageContext, locale);
String message = null;
if (args == null) {
message = resources.getMessage(userLocale, key);
} else {
message = resources.getMessage(userLocale, key, args);
}
if ((message == null)  log.isDebugEnabled()) {
// log missing key to ease debugging
log.debug(resources.getMessage(message.resources, key,
bundle, locale));
}
return message;
}

When the bean:message tag is calling this method, the bundle parameter
has a value of 'otherBundle'.

However, when the bean:write tag calls this method the bundle parameter
is null - hence the ??? errors.foo.bar ??? message in my JSP.

Can someone offer advice on this issue? Do I have my JSP and
struts-config.xml configured correctly?

Any help would be greatly appreciated

Thanks

Sean

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Resource bundles and Struts taglibs

2006-08-23 Thread O'Shea, Sean
Hi Niall,

Thanks again for your help - your suggestion worked.

Sean 

-Original Message-
From: Niall Pemberton [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, August 23, 2006 11:03 AM
To: Struts Users Mailing List
Subject: Re: Resource bundles and Struts taglibs

On 8/23/06, O'Shea, Sean Sean.O'[EMAIL PROTECTED] wrote:
 Hi all,

 I'm using struts 1.2.9 and I'm having some trouble with resource
 bundles. My JSP looks like this:

 %@ include file=../taglibs.jsp %
 logic:messagesPresent
 h3 class=redbean:message key=errors.header
 bundle=otherBundle//h3
 bean:message key=errors.subheader bundle=otherBundle /
 ul
 html:messages id=error
 libean:write name=error
 bundle=otherBundle //li
 /html:messages
 /ul
 hr
 /logic:messagesPresent

 I'm plugging my resources into my struts-config.xml like this:

 message-resources parameter=resources.ApplicationResources
 null=false/
 message-resources key=otherBundle parameter=resources.OtherBundle
 null=false/

 Both the bean:message messages get outputted as expected. This means
 that the otherBundle resources are definitely registered with the
 application.

 However, the bean:write message does not get outputted as expected - I
 get a ??? errors.foo.bar ??? message on the JSP

Its the html:messages tag that is converting the keys in your error
messages into the text - bean:write is just accessing the page scope
variable that the text has been stored under and writing it out. The
bundle attribute for bean:write is for use with the formatKey
attribute.

You need to specify the bundle on the html:messages tag:

  html:messages id=error bundle=otherBundle
libean:write name=error //li
   /html:messages

Niall

 I've debugged the tag libraries and I think both bean:message and
 bean:write call the org.apache.struts.taglib.TagUtils.message method
 detailed below:

 public String message(
 PageContext pageContext,
 String bundle,
 String locale,
 String key,
 Object args[])
 throws JspException {

 MessageResources resources =
 retrieveMessageResources(pageContext, bundle, false);

 Locale userLocale = getUserLocale(pageContext, locale);
 String message = null;
 if (args == null) {
 message = resources.getMessage(userLocale, key);
 } else {
 message = resources.getMessage(userLocale, key, args);
 }
 if ((message == null)  log.isDebugEnabled()) {
 // log missing key to ease debugging
 log.debug(resources.getMessage(message.resources, key,
 bundle, locale));
 }
 return message;
 }

 When the bean:message tag is calling this method, the bundle parameter
 has a value of 'otherBundle'.

 However, when the bean:write tag calls this method the bundle
parameter
 is null - hence the ??? errors.foo.bar ??? message in my JSP.

 Can someone offer advice on this issue? Do I have my JSP and
 struts-config.xml configured correctly?

 Any help would be greatly appreciated

 Thanks

 Sean

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: JavaScript validation errors

2006-08-14 Thread O'Shea, Sean
Hi Srinivas,

I tried setting my login form like this:

html:form action=login onsubmit=return validateLoginForm(this);
.
/html:form
html:javascript formName=loginForm/

... Still no luck in getting the javascript function called though. I've
checked the source of the generated page and it looks like the
validateLoginForm function is getting generated:

function validateLoginForm(form) {

if (bCancel) 
  return true; 
else 
 var formValidationResult;
   formValidationResult = validateRequired(form); 
 return (formValidationResult == 1);
   } 

function loginForm_required () { 
 this.a0 = new Array(SSN, SSN is required., new Function
(varName,  return this[varName];));
 this.a1 = new Array(password, Password is required., new
Function (varName,  return this[varName];));
}

The generated validateRequired function looks like this:

function validateRequired(form) {
var isValid = true;
var focusField = null;
var i = 0;
var fields = new Array();
var formName = form.getAttributeNode(name);

oRequired = eval('new ' + formName.value + '_required()');

.

I'm guessing the intent of the eval('new ' + formName.value +
'_required()'); line is to call the loginForm_required function?

I made a little change to the validateRequired.js in the
org.apache.commons.validator.javascript to alert when the function is
called:

/*$RCSfile: validateRequired.js,v $ $Revision: 1.13 $ $Date:
2004/03/28 16:53:21 $ */
/**
*  Check to see if fields must contain a value.
* Fields are not checked if they are disabled.
* p
* @param form The form validation is taking place on.
*/

function validateRequired(form) {
alert(Calling required )
.

But this doesn't even get called. 

My browser says that there is an error on line 1081 on the page -
looking at this line I see this:

//End -- 
/script

My browser says it expects a '}' - it appears that there is a missing
closing brace somewhere in the code?

Has anyone else come across this problem?

Thanks

Sean

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 14, 2006 5:39 AM
To: Struts Users Mailing List
Subject: RE: JavaScript validation errors





Hi sean,

  i think if you put   onsubmit=return validateLoginForm(this); it
works
fine with client(front-end validation)side and if you remove onsubmit
from
jsp then it works fine with server(backend validation)may be this
helps
you

Thanks,
Srinivas.




 

 O'Shea, Sean

 Sean.O'[EMAIL PROTECTED]

 com
To 
   user@struts.apache.org

 08/12/2006 12:11
cc 
 AM

 
Subject 
   RE: JavaScript validation errors

 Please respond to

   Struts Users

   Mailing List

 [EMAIL PROTECTED]

  he.org

 

 





Hi,

I'm not writing the JavaScript code myself, so I cannot include a check
like you suggested. The JavaScript is being automatically generated
using the html:javascript tag. The generated validateRequired method
is taken directly from the commons-validator.jar:

function validateRequired(form) {
var isValid = true;
var focusField = null;
var i = 0;
var fields = new Array();
var formName = form.getAttributeNode(name);

oRequired = eval('new ' + formName.value + '_required()');

for (x in oRequired) {
var field = form[oRequired[x][0]];

if ((field.type == 'hidden' ||
field.type == 'text' ||
field.type == 'textarea' ||
field.type == 'file' ||
field.type == 'checkbox' ||
field.type == 'select-one' ||
field.type == 'password') 
field.disabled == false) {

var value = '';
// get field's value
if (field.type == select-one) {
var si = field.selectedIndex;
if (si = 0) {
value = field.options[si].value;
}
} else if (field.type == 'checkbox') {
if (field.checked) {
value = field.value;
}
} else {
value = field.value;
}

if (trim(value).length == 0) {

if (i == 0) {
focusField = field;
}
fields[i++] = oRequired[x][1];
isValid = false;
}
} else if (field.type == select-multiple) {
var numOptions = field.options.length;
lastSelected=-1;
for(loop=numOptions-1;loop=0;loop--) {
if(field.options[loop

RE: JavaScript validation errors

2006-08-14 Thread O'Shea, Sean
Hi all,

It appears a faulty JavaScript function was being plugged in elsewhere
in the application. This was causing JavaScript rendering errors when
the page loaded. I've removed the faulty script and the client side
validation works perfectly.

Thanks for all the suggestions

Sean 

-Original Message-
From: O'Shea, Sean 
Sent: Monday, August 14, 2006 10:32 AM
To: user@struts.apache.org
Subject: RE: JavaScript validation errors

Hi Srinivas,

I tried setting my login form like this:

html:form action=login onsubmit=return validateLoginForm(this);
.
/html:form
html:javascript formName=loginForm/

... Still no luck in getting the javascript function called though. I've
checked the source of the generated page and it looks like the
validateLoginForm function is getting generated:

function validateLoginForm(form) {

if (bCancel) 
  return true; 
else 
 var formValidationResult;
   formValidationResult = validateRequired(form); 
 return (formValidationResult == 1);
   } 

function loginForm_required () { 
 this.a0 = new Array(SSN, SSN is required., new Function
(varName,  return this[varName];));
 this.a1 = new Array(password, Password is required., new
Function (varName,  return this[varName];));
}

The generated validateRequired function looks like this:

function validateRequired(form) {
var isValid = true;
var focusField = null;
var i = 0;
var fields = new Array();
var formName = form.getAttributeNode(name);

oRequired = eval('new ' + formName.value + '_required()');

.

I'm guessing the intent of the eval('new ' + formName.value +
'_required()'); line is to call the loginForm_required function?

I made a little change to the validateRequired.js in the
org.apache.commons.validator.javascript to alert when the function is
called:

/*$RCSfile: validateRequired.js,v $ $Revision: 1.13 $ $Date:
2004/03/28 16:53:21 $ */
/**
*  Check to see if fields must contain a value.
* Fields are not checked if they are disabled.
* p
* @param form The form validation is taking place on.
*/

function validateRequired(form) {
alert(Calling required )
.

But this doesn't even get called. 

My browser says that there is an error on line 1081 on the page -
looking at this line I see this:

//End -- 
/script

My browser says it expects a '}' - it appears that there is a missing
closing brace somewhere in the code?

Has anyone else come across this problem?

Thanks

Sean

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 14, 2006 5:39 AM
To: Struts Users Mailing List
Subject: RE: JavaScript validation errors





Hi sean,

  i think if you put   onsubmit=return validateLoginForm(this); it
works
fine with client(front-end validation)side and if you remove onsubmit
from
jsp then it works fine with server(backend validation)may be this
helps
you

Thanks,
Srinivas.




 

 O'Shea, Sean

 Sean.O'[EMAIL PROTECTED]

 com
To 
   user@struts.apache.org

 08/12/2006 12:11
cc 
 AM

 
Subject 
   RE: JavaScript validation errors

 Please respond to

   Struts Users

   Mailing List

 [EMAIL PROTECTED]

  he.org

 

 





Hi,

I'm not writing the JavaScript code myself, so I cannot include a check
like you suggested. The JavaScript is being automatically generated
using the html:javascript tag. The generated validateRequired method
is taken directly from the commons-validator.jar:

function validateRequired(form) {
var isValid = true;
var focusField = null;
var i = 0;
var fields = new Array();
var formName = form.getAttributeNode(name);

oRequired = eval('new ' + formName.value + '_required()');

for (x in oRequired) {
var field = form[oRequired[x][0]];

if ((field.type == 'hidden' ||
field.type == 'text' ||
field.type == 'textarea' ||
field.type == 'file' ||
field.type == 'checkbox' ||
field.type == 'select-one' ||
field.type == 'password') 
field.disabled == false) {

var value = '';
// get field's value
if (field.type == select-one) {
var si = field.selectedIndex;
if (si = 0) {
value = field.options[si].value;
}
} else if (field.type == 'checkbox') {
if (field.checked) {
value = field.value;
}
} else {
value = field.value;
}

if (trim(value).length == 0

JavaScript validation errors

2006-08-11 Thread O'Shea, Sean
Hi all,

I'm using struts 1.2.7 with commons-validator-1.1.4 and I'm running into
a few generated JavaScript errors. Here's what my JSP looks like:

html:javascript formName=loginForm /
html:form action=/login method=POST
  table border=0 cellspacing=5
tr
  th align=right
bean:message key=login.ssn/:
  /th
  td align=left
html:text property=SSN/bean:message
key=login.correctssn/
  /td
/tr
tr
  th align=right
bean:message key=login.password/:
  /th
  td align=left
html:password property=password/bean:message
key=login.correctpw/
  /td
/tr
tr
  td align=right
input type=submit value=bean:message
key=login.button//
  /td
  td align=left
input type=reset/
  /td
/tr
  /table
/html:form

Here's what my action mapping looks like:

action path=/login name=loginForm
type=LoginAction
scope=request validate=true
input=login
.
/action

This is what my form bean looks like:

form-bean name=loginForm
type=org.apache.struts.validator.DynaValidatorForm
form-property name=SSN
type=java.lang.String /
form-property name=password
type=java.lang.String /
/form-bean

My form validations look like this:

form name=loginForm
field property=SSN depends=required
arg key=login.ssn position=0/
/field
field property=password depends=required
arg key=login.password position=0/
/field
/form

When I try to submit my loginForm. my server die validations work fine,
but the JavaScript does not get executed. From looking at the generated
source I see this:

script type=text/javascript language=Javascript1.1 

!-- Begin 

 var bCancel = false; 

function validateLoginForm(form) {

if (bCancel) 
  return true; 
else 
 var formValidationResult;
   formValidationResult = validateRequired(form); 
 return (formValidationResult == 1);
   } 

function loginForm_required () { 
 this.a0 = new Array(SSN, SSN is required., new Function
(varName,  return this[varName];));
 this.a1 = new Array(password, Password is required., new
Function (varName,  return this[varName];));
} 

Either the JavaScript is not getting called, or the generated JavaScript
does not match up. Could it be something to do with the html:javasctipt
tag? Looking at the source I have for the JavascriptValidatorTag class I
see this version:

 * $Id: JavascriptValidatorTag.java 165208 2005-04-28 21:41:45Z mrdon $ 

All help would be greatly appreciated.

Thanks

Sean 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: JavaScript validation errors

2006-08-11 Thread O'Shea, Sean
Hi Adam,

I changed my login form to look like this:

 html:form action=/login method=POST onsubmit=return
validateLoginForm(this);
  table border=0 cellspacing=5
tr
  th align=right
bean:message key=login.ssn/:
  /th
  td align=left
html:text property=SSN/bean:message
key=login.correctssn/
  /td
/tr
tr
  th align=right
bean:message key=login.password/:
  /th
  td align=left
html:password property=password/bean:message
key=login.correctpw/
  /td
/tr
tr
  td align=right
input type=submit value=bean:message
key=login.button//
  /td
  td align=left
input type=reset/
  /td
/tr
  /table
/html:form

But still no luck. My server side validation still works fine, but the
client side validation does not seem to execute.
Even when I look at the source for my JSP I can see the call to the
JavaScript function:

form name=loginForm method=POST action=/MySampleApp/sample/login
onsubmit=return validateLoginForm(this);

Its as if the variables are not getting loaded into the JavaScript
function, or the function is not getting called at all.

Anyone have any ideas on this?

Thanks again

Sean



-Original Message-
From: Adam Gordon [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 11, 2006 11:56 AM
To: Struts Users Mailing List
Subject: Re: JavaScript validation errors

Sean-

You need to add an onsubmit attribute to your html:form element that 
calls the validation function.  Specifically, IIRC, it needs to say:
onsubmit=return validateForm(this);

happy coding,

-adam

O'Shea, Sean wrote:
 Hi all,

 I'm using struts 1.2.7 with commons-validator-1.1.4 and I'm running
into
 a few generated JavaScript errors. Here's what my JSP looks like:

 html:javascript formName=loginForm /
 html:form action=/login method=POST
   table border=0 cellspacing=5
 tr
   th align=right
   bean:message key=login.ssn/:
   /th
   td align=left
   html:text property=SSN/bean:message
 key=login.correctssn/
   /td
 /tr
 tr
   th align=right
   bean:message key=login.password/:
   /th
   td align=left
   html:password property=password/bean:message
 key=login.correctpw/
   /td
 /tr
 tr
   td align=right
   input type=submit value=bean:message
 key=login.button//
   /td
   td align=left
   input type=reset/
   /td
 /tr
   /table
 /html:form

 Here's what my action mapping looks like:

   action path=/login name=loginForm
 type=LoginAction
   scope=request validate=true
 input=login
 .
   /action

 This is what my form bean looks like:

   form-bean name=loginForm
 type=org.apache.struts.validator.DynaValidatorForm
   form-property name=SSN
 type=java.lang.String /
   form-property name=password
 type=java.lang.String /
   /form-bean

 My form validations look like this:

   form name=loginForm
   field property=SSN depends=required
   arg key=login.ssn position=0/
   /field
   field property=password depends=required
   arg key=login.password position=0/
   /field
   /form

 When I try to submit my loginForm. my server die validations work
fine,
 but the JavaScript does not get executed. From looking at the
generated
 source I see this:

 script type=text/javascript language=Javascript1.1 

 !-- Begin 

  var bCancel = false; 

 function validateLoginForm(form) {

 if (bCancel) 
   return true; 
 else 
  var formValidationResult;
formValidationResult = validateRequired(form); 
  return (formValidationResult == 1);
} 

 function loginForm_required () { 
  this.a0 = new Array(SSN, SSN is required., new Function
 (varName,  return this[varName];));
  this.a1 = new Array(password, Password is required., new
 Function (varName,  return this[varName];));
 } 

 Either the JavaScript is not getting called, or the generated
JavaScript
 does not match up. Could it be something to do with the
html:javasctipt
 tag? Looking at the source I have for the JavascriptValidatorTag class
I
 see this version:

  * $Id: JavascriptValidatorTag.java 165208 2005-04-28 21:41:45Z mrdon
$ 

 All help would be greatly appreciated.

 Thanks

 Sean 

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
   

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL

RE: JavaScript validation errors

2006-08-11 Thread O'Shea, Sean
Hi,

I'm not writing the JavaScript code myself, so I cannot include a check
like you suggested. The JavaScript is being automatically generated
using the html:javascript tag. The generated validateRequired method
is taken directly from the commons-validator.jar:

function validateRequired(form) {
var isValid = true;
var focusField = null;
var i = 0;
var fields = new Array();
var formName = form.getAttributeNode(name);

oRequired = eval('new ' + formName.value + '_required()');

for (x in oRequired) {
var field = form[oRequired[x][0]];

if ((field.type == 'hidden' ||
field.type == 'text' ||
field.type == 'textarea' ||
field.type == 'file' ||
field.type == 'checkbox' ||
field.type == 'select-one' ||
field.type == 'password') 
field.disabled == false) {

var value = '';
// get field's value
if (field.type == select-one) {
var si = field.selectedIndex;
if (si = 0) {
value = field.options[si].value;
}
} else if (field.type == 'checkbox') {
if (field.checked) {
value = field.value;
}
} else {
value = field.value;
}

if (trim(value).length == 0) {

if (i == 0) {
focusField = field;
}
fields[i++] = oRequired[x][1];
isValid = false;
}
} else if (field.type == select-multiple) { 
var numOptions = field.options.length;
lastSelected=-1;
for(loop=numOptions-1;loop=0;loop--) {
if(field.options[loop].selected) {
lastSelected = loop;
value = field.options[loop].value;
break;
}
}
if(lastSelected  0 || trim(value).length == 0) {
if(i == 0) {
focusField = field;
}
fields[i++] = oRequired[x][1];
isValid=false;
}
} else if ((field.length  0)  (field[0].type == 'radio'
|| field[0].type == 'checkbox')) {
isChecked=-1;
for (loop=0;loop  field.length;loop++) {
if (field[loop].checked) {
isChecked=loop;
break; // only one needs to be checked
}
}
if (isChecked  0) {
if (i == 0) {
focusField = field[0];
}
fields[i++] = oRequired[x][1];
isValid=false;
}
}
}
if (fields.length  0) {
   focusField.focus();
   alert(fields.join('\n'));
}
return isValid;
}

// Trim whitespace from left and right sides of s.
function trim(s) {
return s.replace( /^\s*/,  ).replace( /\s*$/,  );
}

Sean

-Original Message-
From: Monkeyden [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 11, 2006 1:57 PM
To: Struts Users Mailing List
Subject: Re: JavaScript validation errors

Are you returning false when there is an error in the validation?

if(userName.trim().length() == 0){
alert(Pathetic, technologically inept users must enter a user
name.);
return false;
}


On 8/11/06, O'Shea, Sean Sean.O'[EMAIL PROTECTED] wrote:

 Hi Adam,

 I changed my login form to look like this:

 html:form action=/login method=POST onsubmit=return
 validateLoginForm(this);
 table border=0 cellspacing=5
tr
  th align=right
bean:message key=login.ssn/:
  /th
  td align=left
html:text property=SSN/bean:message
 key=login.correctssn/
  /td
/tr
tr
  th align=right
bean:message key=login.password/:
  /th
  td align=left
html:password property=password/bean:message
 key=login.correctpw/
  /td
/tr
tr
  td align=right
input type=submit value=bean:message
 key=login.button//
  /td
  td align=left
input type=reset/
  /td
/tr
 /table
 /html:form

 But still no luck. My server side validation still works fine, but the
 client side validation does not seem to execute.
 Even when I look at the source for my JSP I can see the call to the
 JavaScript function:

 form name=loginForm method=POST
action=/MySampleApp/sample/login
 onsubmit=return validateLoginForm(this);

 Its as if the variables are not getting loaded into the JavaScript
 function, or the function is not getting called at all