Return-Path: Delivered-To: apmail-myfaces-users-archive@www.apache.org Received: (qmail 39347 invoked from network); 3 Jan 2007 20:29:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Jan 2007 20:29:48 -0000 Received: (qmail 47406 invoked by uid 500); 3 Jan 2007 20:29:50 -0000 Delivered-To: apmail-myfaces-users-archive@myfaces.apache.org Received: (qmail 47372 invoked by uid 500); 3 Jan 2007 20:29:50 -0000 Mailing-List: contact users-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Discussion" Delivered-To: mailing list users@myfaces.apache.org Received: (qmail 47361 invoked by uid 99); 3 Jan 2007 20:29:50 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Jan 2007 12:29:50 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [203.109.151.109] (HELO email.rhe.co.nz) (203.109.151.109) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Jan 2007 12:29:40 -0800 Received: from [192.168.50.47] ([203.109.151.126]) by email.rhe.co.nz (Lotus Domino Release 7.0.1) with ESMTP id 2007010409291574-129357 ; Thu, 4 Jan 2007 09:29:15 +1300 Message-ID: <459C1221.2020600@rhe.co.nz> Date: Thu, 04 Jan 2007 09:29:21 +1300 From: Simon Kitching User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 To: MyFaces Discussion Subject: Re: Inline validation method References: <8088224.post@talk.nabble.com> <459AC93F.3040201@rhe.co.nz> <75c123340701030544h2414b3bcgb2b745866f8c1e30@mail.gmail.com> In-Reply-To: <75c123340701030544h2414b3bcgb2b745866f8c1e30@mail.gmail.com> X-MIMETrack: Itemize by SMTP Server on RHEDomino2/RHE(Release 7.0.1|January 17, 2006) at 04/01/2007 09:29:15 a.m., Serialize by Router on RHEDomino2/RHE(Release 7.0.1|January 17, 2006) at 04/01/2007 09:29:36 a.m., Serialize complete at 04/01/2007 09:29:36 a.m. Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-8859-1; format=flowed X-Virus-Checked: Checked by ClamAV on apache.org Thanks David. Is this "validator" attribute something added in JSF 1.2? I'm sure it doesn't exist in JSF 1.1 (which is what MyFaces 1.1.x supports). The article doesn't specify what JSF version each of the demonstrated features is available in.. Cheers, Simon David Chandler wrote: > FYI, here's the link to the original article: > > http://www-128.ibm.com/developerworks/library/j-jsf3/ > > It simply illustrates inline validation in JSF 1.1, and Simon is > correct that the bean validator method gets passed a component > reference (along with faces context, and an Object value to validate). > > In practice, the easiest way to code the correct signature for a bean > validator method is to use your IDE to auto-create the validate() > method by having your managed bean implement the > javax.faces.validator.Validator interface. The bean doesn't actually > have to implement the interface, nor does the method have to be named > validate, but it's a convenient way to create the code. > > /dmc > > On 1/2/07, Simon Kitching wrote: >> lightbulb432 wrote: >> > The text below is a modified excerpt from the IBM article about JSF >> > validation...I'm wondering what exactly they're trying to say. What >> do they >> > mean by the "value [has] to be generically evaluated with a component >> > association in lieu of directly inspecting the local bean >> > properties"...what's the issue here? >> >> It would be nice if you gave a URL to the quoted article. I guess this >> is some IBM proposal to add a feature to JSF (presumably for the JSF 1.3 >> or 2.0 releases). >> >> At the point that validation runs, the "update model" phase has not >> executed. So if you were to try to access the managed-bean property >> specified in the "value" attribute, it wouldn't yet have the new value. >> This is really the *point* of validation - checking before updating >> model. >> >> So to get the value to be validated, you must ignore whatever the >> "value" attribute points to, and instead get the data directly out of >> the JSF component. >> >> I presume their proposed "validator" method gets passed the relevant >> UIComponent object (an HtmlInputText in this case). >> >> > >> > >> > >> > The method would then be used in the JSF tag via the validator >> attribute as >> > shown here: >> > >> > > > value="#{UserRegistration.user.email}" >> > validator="#{UserRegistration.validateEmail}" >> > required="true"> >> > >> > >> > The validateEmail method is used by JSF to perform custom validation >> on an >> > inputText component value bound to a user.email model property. If the >> > e-mail format is invalid, then a message is added to the faces >> context for >> > the associated component. Now, considering that this validation >> method is >> > actually part of the backing bean, why does the value have to be >> generically >> > evaluated with a component association in lieu of directly >> inspecting the >> > local bean properties? For a hint, look at the prior lifecycle figures. >> > Don't worry if you can't quite figure it out right now; we'll >> explain it all >> > at the end of the article. >> > >> > Why, if a validation method is actually part of a backing bean, must >> its >> > value be generically evaluated with a component association? >> > >> > The trick here is that, although the validateEmail inline validation >> method >> > is part of the actual backing bean, the method must reference the >> value via >> > component association rather than accessing the local properties >> directly. >> > Because validation occurs before the component values are bound to >> the model >> > (in the update model values phase), the model is in an unknown state. >> > Therefore, you must write the inline custom validation logic as if >> it were >> > dealing with validation in a custom Validator object. This is also >> explains >> > the requirement of maintaining the same method signature. >> >> > >