Return-Path: Delivered-To: apmail-beehive-user-archive@www.apache.org Received: (qmail 46798 invoked from network); 19 Dec 2007 16:08:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Dec 2007 16:08:28 -0000 Received: (qmail 65043 invoked by uid 500); 19 Dec 2007 16:08:17 -0000 Delivered-To: apmail-beehive-user-archive@beehive.apache.org Received: (qmail 65021 invoked by uid 500); 19 Dec 2007 16:08:16 -0000 Mailing-List: contact user-help@beehive.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Beehive Users" Delivered-To: mailing list user@beehive.apache.org Received: (qmail 65010 invoked by uid 99); 19 Dec 2007 16:08:16 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Dec 2007 08:08:16 -0800 X-ASF-Spam-Status: No, hits=-1.0 required=10.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of Paul.Gorbas@sprint.com designates 216.32.181.16 as permitted sender) Received: from [216.32.181.16] (HELO outbound6-wa4-R.bigfish.com) (216.32.181.16) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Dec 2007 16:08:03 +0000 Received: from outbound6-wa4.bigfish.com (localhost.localdomain [127.0.0.1]) by outbound6-wa4-R.bigfish.com (Postfix) with ESMTP id 8F22D186BA8C; Wed, 19 Dec 2007 16:07:31 +0000 (UTC) Received: from mail142-wa4-R.bigfish.com (si1-wa4 [10.8.14.5]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by outbound6-wa4.bigfish.com (Postfix) with ESMTP id 850E116806E; Wed, 19 Dec 2007 16:07:31 +0000 (UTC) Received: from mail142-wa4 (localhost.localdomain [127.0.0.1]) by mail142-wa4-R.bigfish.com (Postfix) with ESMTP id 56DD9880C29; Wed, 19 Dec 2007 16:07:31 +0000 (UTC) X-BigFish: V X-MS-Exchange-Organization-Antispam-Report: OrigIP: 207.40.188.13;Service: EHS Received: by mail142-wa4 (MessageSwitch) id 1198080451297076_9992; Wed, 19 Dec 2007 16:07:31 +0000 (UCT) Received: from smtpgw5.sprintspectrum.com (smtpgw5.sprintspectrum.com [207.40.188.13]) by mail142-wa4.bigfish.com (Postfix) with ESMTP id 1F81364807B; Wed, 19 Dec 2007 16:07:31 +0000 (UTC) Received: from mailhost.sprintspectrum.com (smtpgw7.it.sprintspectrum.com [207.40.65.55]) by smtpgw5.sprintspectrum.com (8.12.10/8.12.8) with ESMTP id lBJG735T000746; Wed, 19 Dec 2007 10:07:04 -0600 (CST) Received: from plswe01a.ad.sprint.com (PLSWE01A.corp.sprint.com [144.226.242.149]) by mailhost.sprintspectrum.com (Switch-3.2.5/Switch-3.2.5) with ESMTP id lBJG7LTI027684; Wed, 19 Dec 2007 10:07:21 -0600 (CST) Received: from pdawh03a.ad.sprint.com (144.226.110.70) by plswe01a.ad.sprint.com (144.226.242.149) with Microsoft SMTP Server (TLS) id 8.0.751.0; Wed, 19 Dec 2007 10:03:30 -0600 Received: from PLSWM06C.ad.sprint.com ([144.226.242.97]) by pdawh03a.ad.sprint.com ([144.226.110.70]) with mapi; Wed, 19 Dec 2007 10:07:20 -0600 From: "Gorbas, Paul H [IT]" To: Beehive Users , "dnataraj@gmail.com" Date: Wed, 19 Dec 2007 10:07:20 -0600 Subject: RE: Beehive Form Field Validation Thread-Topic: Beehive Form Field Validation Thread-Index: AchCTrXn8wsc/sApTzy32EgzCfOnLgACkJlg Message-ID: <93301C8F20B2954F814C4369B291437109D674E7@PLSWM06C.ad.sprint.com> References: <008401c8424e$b7471370$25d53a50$@com> In-Reply-To: <008401c8424e$b7471370$25d53a50$@com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Checked: Checked by ClamAV on apache.org This may help - note I wrote for myself and posted to the workshop users gr= oup a while back: Here's how to implement data validation in Workshop 10.1. There are severa= l ways to validate, but this is server side Validation of a form encapsulat= ed in a data bean. Below is what is working for me and I am sharing it in = hopes it will aid others: 1) Modify ( or create ) your form bean to implement the Validatable interfa= ce. public class ProvisionData implements Serializable, Validatable { .... 2) In your data bean implement the Validatable method. It doesn't need to = do anything, you can just put in a stub. public void validate( ActionMapping arg0, HttpServletRequest arg1, Actio= nMessages arg2 ) { } 3) In the Page Flow Explorer, right click on any Action that takes the data= BEan as a input parameter, then select from the pop-up menu "Validation Rul= es" and ActionFromScope from the sub pop-up menu. 4) The Validation Rules Wizard opens, in it you will see a tree of all the = properties defined in your dataBean. 5) In the tree, below each property node, is a "All" Node - this is for loc= alization and you can define specific language nodes if you wish. 6) Any exiting Rules you have previously defined will show up. You can cli= ck on the rule to modify it's behavior. 7) To add a new rule, right click on the ALl Node ( or a new localization n= ode you created) and select "Add Rule", and fill out the form the wizard ge= nerates for you to fill in specifying the type of validation rule you creat= ed. 8) When the wizard closes, because I choose ActionFromScope in step 3, the = action methods annotation gets modified to include the validation rules you= defined. Specially it adds ( or modifies) the validatableProperties argum= ent of the Jpf.Action annotation. 9) The one item the wizard was not generating is the validationErrorForward= parameter of you Jpf.Action annotation, but it is easy enough to add it in= yourself. ( A common scenario is that you were on a user input page that p= ost to your action method on a form submit, on success it will go to the pa= ge your forwards.@Jpf.Forward argument specified if it failed one or more v= alidation steps, then it will go to your validationErrorForward.@Jpf.Forwar= d path ( typically returning back to same input page again ). 10) Here is an example of a annotation after the wizard is done with it ( I= added white space for easier reading ). In the below example, I have defi= ned 3 validations rules. Two rules are defined on the property "subType", = and another rule is defined for the property "subid" @Jpf.Action ( forwards =3D { @Jpf.Forward(name =3D "addDone", path =3D "rtp_Input.js= p") } , validationErrorForward=3D@Jpf.Forward( name=3D"validationFail" , path=3D"rtp_AddProvisioningData.j= sp" ) , validatableProperties =3D { @Jpf.ValidatableProperty( propertyName =3D= "subType" , validateMask =3D @= Jpf.ValidateMask(message =3D "Subscripton Type must be one of these values:= [A,E,F,I,N,U,V,X,B,C,H,M,P,Z,1-9]", regex =3D "[A,E,F,I,N,U,V,X,B,C,H,M,P,= Z,1-9]") , validateMaxLength = =3D @Jpf.ValidateMaxLength(message =3D "Subscription Type Code is a single = character.", chars =3D 1) ) , @Jpf.ValidatableProperty( propertyName=3D"su= bid" , validateMaxLength= =3D@Jpf.ValidateMaxLength(message=3D"Subscription Id max length is 16 chara= cters.", chars=3D16) ) } ) 11) Your almost done - as it is this will work, if a validation rule fails = it will call your dataBeans validate() method ( where I suppose you could d= o some special validation handling ), then the server will serve up what ev= ery page your up whatever page your validationErrorForward specified. 12) To actually have the error message displayed on you served up page you = will need to and additional netui tag(s) for each property you created a ru= le for. The tag goes in your jsp page like this "" and the value for the key must equal the propertyName in the rules Va= lidatableProperty tag which much match a parameter name of one of your data= Beans member properties. 13) When all this is in place the Page Flow editor overview will display th= e error path from your action ( along with your other page flows). When yo= ur input page is initially hit, the jsp's netui:error will display nothing. 14) If you submit the form and validate one or more rules, then the input p= age gets displayed again, and the "" tag will d= isplay one or more errors. In my example I used in step 10 above, I had tw= o netui:error tags in my input jsp page - one for the subType, a second for= the subid. If I submit a page violating all 3 rules, then the will display BOTH messages it defined, while the will display its single message. Good luck! -Paul G. -----Original Message----- From: Deepak Natarajan [mailto:dnataraj@gmail.com] Sent: Wednesday, December 19, 2007 8:52 AM To: user@beehive.apache.org Subject: Beehive Form Field Validation Hi - I have a very basic question about form validation in Beehive. Any help/gui= dance will be much appreciated. My understanding is that Beehive uses/extends Apache Commons Validatior fra= mework. According to the Beehive Javadocs for validationRules (http://beehi= ve.apache.org/docs/1.0.2/netui/apidocs/javadoc/org/apache/beehi ve/netui/pageflow/validation/ValidatorRules.html) there are various methods= inherited from FieldChecks such as validateInteger etc. But the correspond= ing annotations to use these methods seem to be missing...or am I confusing= myself here? Can anyone provide a simple example to use these? The beehive= netui samples doesnt have any extensive examples in this area. Also, is it necessary that a form bean properties should be string types an= d not their real domain type (with the conversion ability checked in a cust= om rule)? Its a fundamental question, and the reason I'm asking is that for= a BigDecimal bean property for example, if I enter a String value in the f= orm, a NumberFormatException occurs obviously - since the validation seems = to be done after the property setter is run, not before. Other techniques t= hat I've encountered before are to have validation checks inside the setter= , or some client-side checks etc. For me it seemed intuitive that the @Jpf.= ValidateProperty should have been on the setter (which is where I put it in= itially until the IDE corrected me!) so that before the bean property is se= t, type validation is done - but now when the container does the automatic = conversion to the object type, it fails with a NumberFormatException. What = is a good pattern for this case? Also, any idea which version of Apache commons validator is being used by B= eehive 1.0.2? Thanks in advance Deepak