Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 79574 invoked from network); 5 Oct 2010 18:27:58 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 5 Oct 2010 18:27:58 -0000 Received: (qmail 90106 invoked by uid 500); 5 Oct 2010 18:27:57 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 89796 invoked by uid 500); 5 Oct 2010 18:27:57 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 89787 invoked by uid 99); 5 Oct 2010 18:27:56 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Oct 2010 18:27:56 +0000 X-ASF-Spam-Status: No, hits=0.7 required=10.0 tests=RCVD_IN_DNSWL_NONE,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [76.96.59.212] (HELO qmta14.westchester.pa.mail.comcast.net) (76.96.59.212) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Oct 2010 18:27:49 +0000 Received: from omta01.westchester.pa.mail.comcast.net ([76.96.62.11]) by qmta14.westchester.pa.mail.comcast.net with comcast id F5Us1f00A0EZKEL5E6TUEV; Tue, 05 Oct 2010 18:27:28 +0000 Received: from [192.168.1.202] ([69.143.109.145]) by omta01.westchester.pa.mail.comcast.net with comcast id F6TT1f00M38FjT13M6TTtS; Tue, 05 Oct 2010 18:27:28 +0000 Message-ID: <4CAB6E0D.5030909@christopherschultz.net> Date: Tue, 05 Oct 2010 14:27:25 -0400 From: Christopher Schultz User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.9) Gecko/20100915 Thunderbird/3.1.4 MIME-Version: 1.0 To: Commons Users List Subject: Re: [validator] Possible to configure multiple error messages for a single validator? References: <4CA380E1.4030706@christopherschultz.net> <4CA5FE5B.6040307@christopherschultz.net> In-Reply-To: <4CA5FE5B.6040307@christopherschultz.net> X-Enigmail-Version: 1.1.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 All, Wow, nothing? :( Usually Niall will at least tell me that nobody cares :) - -chris On 10/1/2010 11:29 AM, Christopher Schultz wrote: > All, > > Any suggestions? I've even considered using a multi-valued "msg" using a > comma as a separator for the two. Something like this: > > msg="errors.xhtml.syntax, errors.xhtml.no-end-tag" > > Does anyone have any better ideas? > > Thanks, > -chris > > On 9/29/2010 2:09 PM, Christopher Schultz wrote: >> All, > >> I've been happily using commons-validator 1.3.1 with Struts 1.3 for some >> years, now, and I've recently developed my own custom validator that >> checks for XHTML syntactic validity. Technically, it checks for XHTML >> validity only when the input looks like this: "....": >> everything else validates successfully with no actual XHTML syntax check. > >> Recently, it became clear that users were sometimes forgetting the >> "" at the end of the input. This caused two problems: first, the >> input wasn't being validated as XHTML, and second, when the data was >> then displayed in a web page, it was escaped instead of being rendered >> as actual HTML. > >> My first instinct was to add a "mask" validator that checked for an >> appropriate pattern (that is, "" up front with no trailing >> ""). I implemented that and it works quite well. Then, it >> occurred to me that I might want some other pattern for some reason for >> those fields, and that the correct place for that check ought to be in >> the XHTML validator itself. > >> So I started moving the check described above into my custom validator. >> Everything was fine until I had to render the error message. Since I'm >> doing essentially two checks (one for and matching , and a >> second for actually checking the XHTML syntax), I need two distinct >> error messages. The configuration for a validator only allows one single >> "msg" attribute as shown in my configuration below: > >> > classname="....PossibleXhtmlValidator" >> method="validatePossibleXhtml" >> methodParams="java.lang.Object, >> org.apache.commons.validator.ValidatorAction, >> org.apache.commons.validator.Field, >> org.apache.struts.action.ActionMessages, >> org.apache.commons.validator.Validator, >> javax.servlet.http.HttpServletRequest" >> depends="" >> msg="errors.xhtml" /> > >> I could simply hard-code the error message key into the validator, but >> that seems less maintainable than I'd like it to be. Is it possible to >> provide more than one error message key to a validator like this? > >> Other options for me include creating a custom validator that does >> nothing but check for the ... that won't interfere with, >> say, the "mask" validator. > >> It still seems to me that my goal ought to be a single validator that is >> basically self-contained, rather than having two validators that >> essentially /must/ be used together. > >> Does anyone have any suggestions? > >> Thanks, >> -chris > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org > For additional commands, e-mail: user-help@commons.apache.org > - --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkyrbg0ACgkQ9CaO5/Lv0PD73QCeKJ1yMStcSXf2zmjxZI7Vf2Ju NRwAoL9KqTrjllCW1jJhlLeoohCfxNLg =YBSz -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org