You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by mojoRising <jp...@averoinc.com> on 2008/02/28 22:31:19 UTC
expression validator
(java - struts 2 - JSP - using xml based validation)
I am trying to figure out how to do a simple client side validation
expression, checking that two fields are equal. Could someone help me figure
this out, I am sure it is very simple but I can't find out what I am
missing. I keep getting this error:
SEVERE: The content of element type "field" must match "(field-validator)+".
at (null:46:13)
org.xml.sax.SAXParseException: The content of element type "field" must
match "(field-validator)+".
The two fields I am checking are password and password2. They are defined in
my validation xml as:
<field name="password">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
</field>
<field name="password2">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
<validator type="expression">
password.equals(password2)
<message>Passwords do not match</message>
</validator>
</field>
I also tried these two variations:
<validator type="expression">
<![CDATA[password.equals(password2)]]>
<message>Passwords do not match</message>
</validator>
And:
<validator type="expression">
password == password2
<message>Passwords do not match</message>
</validator>
--
View this message in context: http://www.nabble.com/expression-validator-tp15746472p15746472.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: expression validator
Posted by Dave Newton <ne...@yahoo.com>.
--- Martin Gainty <mg...@hotmail.com> wrote:
> [...]
AFAICT this doesn't do client-side expression validation either. See, there
is no client-side expression validation. My comment was directed at the Roes
Indai person who implied that their tutorial would help the person with the
original question, because it doesn't address the question at all.
> declare the field validator such as the field-name declared in validators
> in
>
FieldValidatorsExampleAction-submitClientSideValidationExample-validation.xm
> l
> <validators>
> <field name="requiredStringValidatorField">
> <field-validator type="requiredstring">
> <param name="trim">true</param>
> <message key="i18n.nothing.here"><![CDATA[ required and must be
> string ]]></message>
> </field-validator>
> </field>
>
> in the jsp setup a textfield which uses the preconfigured
> requiredStringValidatorField as described in this example from
> /validation/clientSideValidationExample.jsp
> <s:textfield label="Required String Validator Field"
> name="requiredStringValidatorField" />
>
> place the returned field error string into s:fielderror with param
> specified
> as the name of the validator item described here
> <h3>Field Error due to 'Required String Validator Field' Will
> Appear
> Here</h3>
> <s:fielderror>
> <s:param value="%{'requiredStringValidatorField'}" />
> </s:fielderror>
> <hr/>
>
> Make sense?
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: expression validator
Posted by Martin Gainty <mg...@hotmail.com>.
declare the field validator such as the field-name declared in validators in
FieldValidatorsExampleAction-submitClientSideValidationExample-validation.xm
l
<validators>
<field name="requiredStringValidatorField">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message key="i18n.nothing.here"><![CDATA[ required and must be
string ]]></message>
</field-validator>
</field>
in the jsp setup a textfield which uses the preconfigured
requiredStringValidatorField as described in this example from
/validation/clientSideValidationExample.jsp
<s:textfield label="Required String Validator Field"
name="requiredStringValidatorField" />
place the returned field error string into s:fielderror with param specified
as the name of the validator item described here
<h3>Field Error due to 'Required String Validator Field' Will Appear
Here</h3>
<s:fielderror>
<s:param value="%{'requiredStringValidatorField'}" />
</s:fielderror>
<hr/>
Make sense?
M--
From: "Dave Newton" <ne...@yahoo.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Friday, February 29, 2008 9:16 AM
Subject: RE: expression validator
> --- Deepak Kumar <de...@roseindia.net> wrote:
> > Here is very good example with running source code.
> >
>
http://www.roseindia.net/struts/struts2/struts-2-client-side-validation-exam
ple.shtml
>
> Hmm, that doesn't seem to do client-side expression validation either,
unless
> I missed it. Perhaps you can point it out.
>
> Dave
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: expression validator
Posted by Dave Newton <ne...@yahoo.com>.
--- Deepak Kumar <de...@roseindia.net> wrote:
> Here is very good example with running source code.
>
http://www.roseindia.net/struts/struts2/struts-2-client-side-validation-example.shtml
Hmm, that doesn't seem to do client-side expression validation either, unless
I missed it. Perhaps you can point it out.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: expression validator
Posted by Deepak Kumar <de...@roseindia.net>.
Hi,
Here is very good example with running source code.
http://www.roseindia.net/struts/struts2/struts-2-client-side-validation-exam
ple.shtml
Thanks
-----Original Message-----
From: Sanjeewa Saman [mailto:sanjeewas@mubasher.net]
Sent: Friday, February 29, 2008 4:36 PM
To: 'Struts Users Mailing List'
Subject: RE: expression validator
Hi,
You can override the default functionality and use , create the
validator.xml such that is can compare strings.
Refer the following site ,
http://struts2issues.blogspot.com/
this will give a complete idea of doing it.
Thanks .
-----Original Message-----
From: mojoRising [mailto:jpiser@averoinc.com]
Sent: Friday, February 29, 2008 4:16 AM
To: user@struts.apache.org
Subject: Re: expression validator
Thanks, I confirmed my syntax, and now it does not do any client side
validation. Do I have this validator in the right place? Here is the
relevant code from my xml file:
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="password">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
</field>
<field name="password2">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
</field>
<validator type="expression">
password2.equals(password)
<message>Password not the same as
Confirmed</message>
</validator>
</validators>
>>From the validator documentation.
<validator type="expression">
email.equals(email2)
<message>Email not the same as email2</message>
</validator>
Regards,
Randy Burgess
Sr. Web Applications Developer
Nuvox Communications
--
View this message in context:
http://www.nabble.com/expression-validator-tp15746472p15747878.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: expression validator
Posted by Sanjeewa Saman <sa...@mubasher.net>.
Hi,
You can override the default functionality and use , create the
validator.xml such that is can compare strings.
Refer the following site ,
http://struts2issues.blogspot.com/
this will give a complete idea of doing it.
Thanks .
-----Original Message-----
From: mojoRising [mailto:jpiser@averoinc.com]
Sent: Friday, February 29, 2008 4:16 AM
To: user@struts.apache.org
Subject: Re: expression validator
Thanks, I confirmed my syntax, and now it does not do any client side
validation. Do I have this validator in the right place? Here is the
relevant code from my xml file:
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="password">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
</field>
<field name="password2">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
</field>
<validator type="expression">
password2.equals(password)
<message>Password not the same as
Confirmed</message>
</validator>
</validators>
>From the validator documentation.
<validator type="expression">
email.equals(email2)
<message>Email not the same as email2</message>
</validator>
Regards,
Randy Burgess
Sr. Web Applications Developer
Nuvox Communications
--
View this message in context:
http://www.nabble.com/expression-validator-tp15746472p15747878.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: expression validator
Posted by Nuwan Chandrasoma <my...@gmail.com>.
Hi,
yes. this is what i did for one of the project i am bit involved.
1. wrote a custom validator
public class PasswordConfirmValidator extends FieldValidatorSupport {
private static Log log =
LogFactory.getLog(PasswordConfirmValidator.class);
private String fieldName2;
public String getFieldName2() {
return fieldName2;
}
public void setFieldName2(String fieldName2) {
this.fieldName2 = fieldName2;
}
public void validate(Object o) throws ValidationException {
String fieldName = getFieldName();
String val = (String) getFieldValue(fieldName, o);
String val2 = (String)getFieldValue(fieldName2,o);
if (!val.equals(val2)) {
addFieldError(fieldName, o);
}
}
}
2. configured the the customer validator in validators.xml
<validator name="passwordconfirm"
class="com.xxx.util.validation.PasswordConfirmValidator"/>
3. add a custom javascript in the form-close-validate.ftl
<#elseif validator.validatorType = "passwordconfirm">
if (field.value != null) {
var value = field.value;
var field2 = form.elements['${validator.fieldName2}'];
var value2 = field2.value;
if (value!=value2) {
addError(field, error);
errors = true;
}
}
4. add a annotation for the field i need to validate.
@CustomValidator(type="passwordconfirm",message = "Confirm password
should be same as password.",parameters = { @ValidationParameter( name =
"fieldName2", value = "password" ) })
Thanks,
Nuwan
Randy Burgess wrote:
> One of the things I love about Struts is that you get validation without
> writing any real validation code. Admittedly it would be nice if you got
> client side validation for expressions. As you know you can create a custom
> validator and for the client side stuff you would have to edit
> form-close-validate.ftl in the xhtml template. String matching javascript is
> trivial to write.
>
> Regards,
> Randy Burgess
> Sr. Web Applications Developer
> Nuvox Communications
>
>
>
>
>> From: mojoRising <jp...@averoinc.com>
>> Reply-To: Struts Users Mailing List <us...@struts.apache.org>
>> Date: Fri, 29 Feb 2008 06:55:51 -0800 (PST)
>> To: <us...@struts.apache.org>
>> Subject: Re: expression validator
>>
>>
>> Thanks. But I still don't understand...According to the link you mentioned it
>> is not possible to do what I was trying to. So, what is the point of this
>> validator if it doesn't do client side validation? And, are you saying that
>> it is not possible to do a simple 'equals' test in client side validation?
>>
>> <validator type="expression">password.equals(password2)
>> <message>Passwords do not match</message>
>> </validator>
>>
>>
>>
>>
>>
>> That validator doesn't do client side validation.
>>
>> Only the following validators are supported:
>>
>> * required validator
>> * requiredstring validator
>> * stringlength validator
>> * regex validator
>> * email validator
>> * url validator
>> * int validator
>> * double validator
>>
>> http://struts.apache.org/2.0.11/docs/pure-javascript-client-side-validation.
>> html
>>
>> Regards,
>> Randy Burgess
>> Sr. Web Applications Developer
>> Nuvox Communications
>> --
>> View this message in context:
>> http://www.nabble.com/expression-validator-tp15746472p15760197.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
>
> This email and any attachments ("Message") may contain legally privileged and/or confidential information. If you are not the addressee, or if this Message has been addressed to you in error, you are not authorized to read, copy, or distribute it, and we ask that you please delete it (including all copies) and notify the sender by return email. Delivery of this Message to any person other than the intended recipient(s) shall not be deemed a waiver of confidentiality and/or a privilege.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: expression validator
Posted by Randy Burgess <RB...@nuvox.com>.
One of the things I love about Struts is that you get validation without
writing any real validation code. Admittedly it would be nice if you got
client side validation for expressions. As you know you can create a custom
validator and for the client side stuff you would have to edit
form-close-validate.ftl in the xhtml template. String matching javascript is
trivial to write.
Regards,
Randy Burgess
Sr. Web Applications Developer
Nuvox Communications
> From: mojoRising <jp...@averoinc.com>
> Reply-To: Struts Users Mailing List <us...@struts.apache.org>
> Date: Fri, 29 Feb 2008 06:55:51 -0800 (PST)
> To: <us...@struts.apache.org>
> Subject: Re: expression validator
>
>
> Thanks. But I still don't understand...According to the link you mentioned it
> is not possible to do what I was trying to. So, what is the point of this
> validator if it doesn't do client side validation? And, are you saying that
> it is not possible to do a simple 'equals' test in client side validation?
>
> <validator type="expression">password.equals(password2)
> <message>Passwords do not match</message>
> </validator>
>
>
>
>
>
> That validator doesn't do client side validation.
>
> Only the following validators are supported:
>
> * required validator
> * requiredstring validator
> * stringlength validator
> * regex validator
> * email validator
> * url validator
> * int validator
> * double validator
>
> http://struts.apache.org/2.0.11/docs/pure-javascript-client-side-validation.
> html
>
> Regards,
> Randy Burgess
> Sr. Web Applications Developer
> Nuvox Communications
> --
> View this message in context:
> http://www.nabble.com/expression-validator-tp15746472p15760197.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
This email and any attachments ("Message") may contain legally privileged and/or confidential information. If you are not the addressee, or if this Message has been addressed to you in error, you are not authorized to read, copy, or distribute it, and we ask that you please delete it (including all copies) and notify the sender by return email. Delivery of this Message to any person other than the intended recipient(s) shall not be deemed a waiver of confidentiality and/or a privilege.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: expression validator
Posted by Dave Newton <ne...@yahoo.com>.
--- mojoRising <jp...@averoinc.com> wrote:
> Thanks. But I still don't understand...According to the link you mentioned
> it is not possible to do what I was trying to. So, what is the point of
this
> validator if it doesn't do client side validation?
Because there are other places to do validation, like the server.
> And, are you saying that it is not possible to do a simple
> 'equals' test in client side validation?
>
> <validator type="expression">password.equals(password2)
> <message>Passwords do not match</message>
> </validator>
The expressions used by the expression validator [1] are OGNL-based
expressions, not JavaScript. It would be *possible*, but JavaScript !=OGNL,
and it's my assumption that nobody wanted to write a JavaScript library that
implements everything available in OGNL.
That said, I suppose one could take a DWR-like Java => JavaScript mapping
layer then write OGNL in JavaScript and hook the two up. I don't know what
the current status of the XWork validation framework re-thinking is, but I'm
sure if something like that was contributed we'd look at it.
Dave
[1] http://struts.apache.org/2.x/docs/expression-validator.html
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: expression validator
Posted by mojoRising <jp...@averoinc.com>.
Thanks. But I still don't understand...According to the link you mentioned it
is not possible to do what I was trying to. So, what is the point of this
validator if it doesn't do client side validation? And, are you saying that
it is not possible to do a simple 'equals' test in client side validation?
<validator type="expression">password.equals(password2)
<message>Passwords do not match</message>
</validator>
That validator doesn't do client side validation.
Only the following validators are supported:
* required validator
* requiredstring validator
* stringlength validator
* regex validator
* email validator
* url validator
* int validator
* double validator
http://struts.apache.org/2.0.11/docs/pure-javascript-client-side-validation.
html
Regards,
Randy Burgess
Sr. Web Applications Developer
Nuvox Communications
--
View this message in context: http://www.nabble.com/expression-validator-tp15746472p15760197.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: expression validator
Posted by Randy Burgess <RB...@nuvox.com>.
That validator doesn't do client side validation.
Only the following validators are supported:
* required validator
* requiredstring validator
* stringlength validator
* regex validator
* email validator
* url validator
* int validator
* double validator
http://struts.apache.org/2.0.11/docs/pure-javascript-client-side-validation.
html
Regards,
Randy Burgess
Sr. Web Applications Developer
Nuvox Communications
> From: mojoRising <jp...@averoinc.com>
> Reply-To: Struts Users Mailing List <us...@struts.apache.org>
> Date: Thu, 28 Feb 2008 14:45:37 -0800 (PST)
> To: <us...@struts.apache.org>
> Subject: Re: expression validator
>
>
> Thanks, I confirmed my syntax, and now it does not do any client side
> validation. Do I have this validator in the right place? Here is the
> relevant code from my xml file:
>
>
> <!DOCTYPE validators PUBLIC
> "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
> "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
>
> <validators>
> <field name="password">
> <field-validator type="requiredstring">
> <message key="requiredstring"/>
> </field-validator>
> </field>
> <field name="password2">
> <field-validator type="requiredstring">
> <message key="requiredstring"/>
> </field-validator>
> </field>
>
> <validator type="expression">
> password2.equals(password)
> <message>Password not the same as Confirmed</message>
> </validator>
>
> </validators>
>
>
>
>
> From the validator documentation.
>
> <validator type="expression">
> email.equals(email2)
> <message>Email not the same as email2</message>
> </validator>
>
> Regards,
> Randy Burgess
> Sr. Web Applications Developer
> Nuvox Communications
>
>
> --
> View this message in context:
> http://www.nabble.com/expression-validator-tp15746472p15747878.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
This email and any attachments ("Message") may contain legally privileged and/or confidential information. If you are not the addressee, or if this Message has been addressed to you in error, you are not authorized to read, copy, or distribute it, and we ask that you please delete it (including all copies) and notify the sender by return email. Delivery of this Message to any person other than the intended recipient(s) shall not be deemed a waiver of confidentiality and/or a privilege.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: expression validator
Posted by mojoRising <jp...@averoinc.com>.
Thanks, I confirmed my syntax, and now it does not do any client side
validation. Do I have this validator in the right place? Here is the
relevant code from my xml file:
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="password">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
</field>
<field name="password2">
<field-validator type="requiredstring">
<message key="requiredstring"/>
</field-validator>
</field>
<validator type="expression">
password2.equals(password)
<message>Password not the same as Confirmed</message>
</validator>
</validators>
>From the validator documentation.
<validator type="expression">
email.equals(email2)
<message>Email not the same as email2</message>
</validator>
Regards,
Randy Burgess
Sr. Web Applications Developer
Nuvox Communications
--
View this message in context: http://www.nabble.com/expression-validator-tp15746472p15747878.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: expression validator
Posted by Randy Burgess <RB...@nuvox.com>.
>From the validator documentation.
<validator type="expression">
<param name="expression">email.equals(email2)</param>
<message>Email not the same as email2</message>
</validator>
Regards,
Randy Burgess
Sr. Web Applications Developer
Nuvox Communications
> From: mojoRising <jp...@averoinc.com>
> Reply-To: Struts Users Mailing List <us...@struts.apache.org>
> Date: Thu, 28 Feb 2008 13:31:19 -0800 (PST)
> To: <us...@struts.apache.org>
> Subject: expression validator
>
>
> (java - struts 2 - JSP - using xml based validation)
> I am trying to figure out how to do a simple client side validation
> expression, checking that two fields are equal. Could someone help me figure
> this out, I am sure it is very simple but I can't find out what I am
> missing. I keep getting this error:
>
> SEVERE: The content of element type "field" must match "(field-validator)+".
> at (null:46:13)
> org.xml.sax.SAXParseException: The content of element type "field" must
> match "(field-validator)+".
>
> The two fields I am checking are password and password2. They are defined in
> my validation xml as:
>
> <field name="password">
> <field-validator type="requiredstring">
> <message key="requiredstring"/>
> </field-validator>
> </field>
> <field name="password2">
> <field-validator type="requiredstring">
> <message key="requiredstring"/>
> </field-validator>
> <validator type="expression">
> password.equals(password2)
> <message>Passwords do not match</message>
> </validator>
> </field>
>
> I also tried these two variations:
>
> <validator type="expression">
> <![CDATA[password.equals(password2)]]>
> <message>Passwords do not match</message>
> </validator>
>
> And:
>
> <validator type="expression">
> password == password2
> <message>Passwords do not match</message>
> </validator>
> --
> View this message in context:
> http://www.nabble.com/expression-validator-tp15746472p15746472.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
This email and any attachments ("Message") may contain legally privileged and/or confidential information. If you are not the addressee, or if this Message has been addressed to you in error, you are not authorized to read, copy, or distribute it, and we ask that you please delete it (including all copies) and notify the sender by return email. Delivery of this Message to any person other than the intended recipient(s) shall not be deemed a waiver of confidentiality and/or a privilege.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org