Return-Path: X-Original-To: apmail-struts-user-archive@www.apache.org Delivered-To: apmail-struts-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CCE91101CF for ; Tue, 5 May 2015 11:05:39 +0000 (UTC) Received: (qmail 98243 invoked by uid 500); 5 May 2015 11:05:38 -0000 Delivered-To: apmail-struts-user-archive@struts.apache.org Received: (qmail 98206 invoked by uid 500); 5 May 2015 11:05:38 -0000 Mailing-List: contact user-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Struts Users Mailing List" Reply-To: "Struts Users Mailing List" Delivered-To: mailing list user@struts.apache.org Received: (qmail 98194 invoked by uid 99); 5 May 2015 11:05:38 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 May 2015 11:05:38 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: message received from 54.76.25.247 which is an MX secondary for user@struts.apache.org) Received: from [54.76.25.247] (HELO mx1-eu-west.apache.org) (54.76.25.247) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 May 2015 11:05:12 +0000 Received: from iron2.lex-com.net (smtp5.lex-com.net [193.159.191.10]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id B98AE24EC0 for ; Tue, 5 May 2015 11:05:09 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.13,372,1427752800"; d="scan'208";a="35556248" Received: from unknown (HELO mucle03.lex-com.net) ([10.89.20.108]) by iron2.lex-com.net with ESMTP; 05 May 2015 13:05:02 +0200 In-Reply-To: <508355143.1228716.1429068470772.JavaMail.yahoo@mail.yahoo.com> References: <982054074.476221.1428927055313.JavaMail.yahoo@mail.yahoo.com> <508355143.1228716.1429068470772.JavaMail.yahoo@mail.yahoo.com> To: "Struts Users Mailing List" MIME-Version: 1.0 Subject: Re: Struts 2 manually call a custom validation in an action X-KeepSent: E6D6B3DC:3EE4F998-C1257E3C:003C6C69; type=4; name=$KeepSent X-Mailer: Lotus Notes Release 8.5.3 September 15, 2011 Message-ID: From: Christoph Nenning Date: Tue, 5 May 2015 13:04:32 +0200 X-MIMETrack: Serialize by Router on MUCLE03/Lexcom_Muenchen/LEXCOM(Release 8.5.3FP6 HF1024|November 01, 2014) at 05.05.2015 13:04:55, Serialize complete at 05.05.2015 13:04:55 Content-Type: multipart/alternative; boundary="=_alternative 003CE2A2C1257E3C_=" X-Virus-Checked: Checked by ClamAV on apache.org --=_alternative 003CE2A2C1257E3C_= Content-Type: text/plain; charset="US-ASCII" > Please see: http://stackoverflow.com/questions/29603916/struts-2- > manually-call-a-custom-validation-in-an-action ~Regards, > ~~Alireza Fattahi > From: Alireza Fattahi > To: Struts Mailing List > Sent: Monday, 13 April 2015, 16:40 > Subject: Struts 2 manually call a custom validation in an action > > We have used struts 2 validation with lots of custom validation to > validate our forms. > > @Validations( > customValidators = > { @CustomValidator(type = "AccountFormat", fieldName > = "accountNo") } > ) > > Also we can can manually validate a form by overriding the validate method > > public void validate(){ > //Username can't be blank > if(username.equals("")){ > addFieldError("username", "The Username can't be empty"); > } > > Is it possible to call the `custom validations` in the `validate()`. > > **Why we need it ?!** > All validation rules are packed in custom validations, which is > perfect. There are some few forms which need to have their own > manual validation. We end up cut and pasting some of custom > validation rules in these manual validation forms too, it would be > best if we could call validations here > ~Regards, > ~~Alireza Fattahi > > You could use ExpressionValidator to call action specific validation methods. It would look like: @Validations( customValidators ={@CustomValidator(type = "AccountFormat")}, expressions = {@ExpressionValidator(expression="myValidationMethod")} ) Regards, Christoph This Email was scanned by Sophos Anti Virus --=_alternative 003CE2A2C1257E3C_=--