Mike,
it seems that I already have reinvented the wheel :) I thought, the compareTo validator supports only the comparison of two components, isn't this true? Regards, Matthias > -----Ursprüngliche Nachricht----- > Von: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Auftrag > von Mike Kienenberger > Gesendet: Freitag, 16. Dezember 2005 20:57 > An: MyFaces Discussion > Betreff: Re: Retrieving component values in validation methods > > > It's set after validation, but you can check the source in > UIInput.java if you want the authoritative answer. You still might > find it easier to see how it was done in compareTo validator rather > than reinventing the wheel. I put the code for "getting" a foreign > component value into its own method. > > On 12/16/05, Matthias Kahlau <[EMAIL PROTECTED]> wrote: > > Hi Mike! > > > > > > Many thanks, but I solved the cross-component validation with a > > validator-method, because there are more than two components > involved in my > > validation. The validator's component is non-immediate, and the > components > > to compare with are either immediate, or non-immediate, but > placed before > > the validator's component. That's why it's possible to use the > > getLocalValue() method of all other components, if the > components are valid. > > If the component to compare with is invalid, the validation is skipped. > > > > > > But what I need to know (independent of the validation > described) is: is the > > local value of a component set after successful conversion, or after > > successful validation? > > > > > > > > Regards, > > > > Matthias > > > > > > > -----Ursprüngliche Nachricht----- > > > Von: [EMAIL PROTECTED] > > > > [mailto:[EMAIL PROTECTED] Auftrag > > > von Mike Kienenberger > > > Gesendet: Freitag, 16. Dezember 2005 18:48 > > > An: MyFaces Discussion > > > Betreff: Re: Retrieving component values in validation methods > > > > > > > > > Matthias, > > > > > > I think your best bet is to look at the compareTo validator source. > > > > > > 1) It might already be doing what you need if you're working with only > > > two components. > > > > > > 2) It's got code to handle all of the cases, regardless of ordering or > > > validation or immediate status. And if not, it's a bug we need to > > > fix :) > > > > > > On 12/15/05, Matthias Kahlau <[EMAIL PROTECTED]> wrote: > > > > Hi! > > > > > > > > Yes, your approach described should work. But there are > other possible > > > > constellations, as I found out in the meantime (see also the > > > email of Simon > > > > Skitching: > > > > > > > http://www.mail-archive.com/users%40myfaces.apache.org/msg13438.ht > > > ml). When > > > > implementing cross-component validation, it's very important to > > > be aware of > > > > the lifecycle and the component update points relative to the > > > lifecycle, and > > > > also that the validators are processed in the order of their > > > occurence in > > > > the form. > > > > > > > > But not only the ordering of the components in the form is > deciding, you > > > > also have to consider the immediate configuration. > Validator methods of > > > > components configured immediate are invoked in the apply > request values > > > > phase, validator methods of components configured > > > none-immediate are invoked > > > > in the process validations phase. > > > > > > > > > > > > Regards, > > > > > > > > Matthias > > > > > > > > > > > > > -----Ursprungliche Nachricht----- > > > > > Von: [EMAIL PROTECTED] > > > > > > > > > [mailto:[EMAIL PROTECTED] Auftrag > > > > > von Conway. Fintan (IT Solutions) > > > > > Gesendet: Donnerstag, 15. Dezember 2005 10:49 > > > > > An: MyFaces Discussion > > > > > Betreff: RE: Retrieving component values in validation methods > > > > > > > > > > > > > > > > > > > > > 2) Which is the right method to get the values of other > > > components in > > > > > > the validator method, getSubmittedValue(), getLocalValue(), > > > dependent > > > > > > on configuration issues (immediate) of the component owning the > > > > > > validator and other components asked in the validator method? > > > > > > > > > > Would the following work for you? > > > > > (Taken directly from "Core Java Server Faces" book) > > > > > > > > > > The trick is to attach the validator to the last of the > components. By > > > > > the time its > > > > > validator is called, the preceding components passed > > > validation and had > > > > > their > > > > > local values set. The last component has passed > conversion, and the > > > > > converted > > > > > value is passed as the Object parameter of the validation method. > > > > > > > > > > Of course, you need to have access to the other > components. You can > > > > > easily > > > > > achieve that access by using a backing bean that contains all > > > components > > > > > of the > > > > > current form. Simply attach the validation method to the > backing bean: > > > > > > > > > > public class BackingBean { > > > > > private UIInput dayInput; > > > > > private UIInput monthInput; > > > > > ... > > > > > > > > > > public void validateDate(FacesContext context, UIComponent > > > > > component, > > > > > Object value) { > > > > > > > > > > int d = ((Integer) dayInput.getLocalValue()).intValue(); > > > > > int m = ((Integer) monthInput.getLocalValue()).intValue(); > > > > > int y = ((Integer) value).intValue(); > > > > > if (!isValidDate(d, m, y)) { > > > > > FacesMessage message = ...; > > > > > throw new ValidatorException(message); > > > > > } > > > > > } > > > > > ... > > > > > } > > > > > > > > > > Note that the value lookup is a bit asymmetric. The last > > > component does > > > > > not > > > > > yet have the local value set since it has not passed validation. > > > > > > > > > > An alternative approach is to attach the validator to a > hidden input > > > > > field that > > > > > comes after all other fields on the form. > > > > > > > > > > <h:inputHidden id="datecheck" validator="#{bb.validateDate}" > > > > > value="needed"/> > > > > > > > > > > The hidden field is rendered as a hidden HTML input > field. When the > > > > > field > > > > > value is posted back, the validator kicks in. (It is > > > essential that you > > > > > supply some > > > > > field value. Otherwise, the component value is never > > > updated.) With this > > > > > approach, the validation function is more symmetrical > since all other > > > > > form > > > > > components already have their local values set. > > > > > > > > > > > > > > > * ** *** ** * ** *** ** * ** *** ** * > > > > > This email and any files transmitted with it are confidential and > > > > > intended solely for the use of the individual or entity > to whom they > > > > > are addressed. > > > > > Any views or opinions presented are solely those of the author, > > > > > and do not necessarily > > > > > represent those of ESB. > > > > > If you have received this email in error please notify the sender. > > > > > > > > > > Although ESB scans e-mail and attachments for viruses, it does > > > > > not guarantee > > > > > that either are virus-free and accepts no liability for any > > > > > damage sustained > > > > > as a result of viruses. > > > > > > > > > > * ** *** ** * ** *** ** * ** *** ** * > > > > > > > > > > > > > > > > >

