You may find it useful. Today I faced similar problem with
validating-two-separate-mandatory-fields.
I ended up using <h:hiddenText value="1" required="true"
validator="#{validating.function}" /> somewhere after these two input
components. So validating function is invoked in processValidations
phase even if input components don't have any value.
tr:hiddenText throws exception if it's value is empty, so i chose to use
"h" taglib instead. Was just going to look into it's code :)Hope it helps. Suhel Rizvi wrote: > > Thanks for the explanation of the code which shows why it doesnt work. > > However if I do take up your suggestion and put the validation on the > second field only then there is one use case where it is a particular > problem; As you may have noticed both my fields are not required > fields - therefore the user can submit a value for the first field > only and the validation on the second field will not execute and the > form will be submitted without the two fields being equal. > > If both fields were required fields then we would not have this > problem but the user requirements in this case are the fields are non > mandatory but if one of them is filled in then the other must match. > > So if I cant use this validator I need to find an alternative way to > solve this problem. > >> From: "Andrew Robinson" <[EMAIL PROTECTED]> >> Reply-To: "MyFaces Discussion" <[email protected]> >> To: "MyFaces Discussion" <[email protected]> >> Subject: Re: [Tomahawk] validateEqual problem for second field >> Date: Tue, 4 Sep 2007 11:12:44 -0600 >> >> I took a look into the code to make sure I knew what was going on and >> here is what I found: >> >> It looks like the problem you are having is due to the design of the >> ValidateEqual class. It is performing its logic in the validation >> phase using the EditableValueHolder.getValue() function. This presents >> a problem on the first component. Reason as follows: >> >> "equal" has an EqualValidator added to it during the view creation >> "equal2" has an EqualValidator added to it during the view creation >> >> during the decode phase, equal and equal2 are decoded and the values >> from the client are stored in the submittedValue property of each >> component. >> >> during the validation phase: >> >> The "equal" component's processValidators method calls the validate >> function. This function converts the submitted value. If there are no >> problems, the validation of the component is called (validateValue >> function). If the component is valid, the local value (setValue) is >> called. >> >> So, at the time that the "equal" is validating, equal2 has not set its >> local value (it is currently null, only the submitted value is set) >> and the submitted value is not converted. >> >> So, equal cannot compare it's local value to equal2's local value >> since equal2 is not yet validated. >> >> This means that in order for the validate compare to and validate >> equal components to work, they have to be on the second component as >> the first component has to be already be validate, and be valid! >> Otherwise, the local value is not set, which is what these validators >> use to validate against. >> >> So the short answer to your question is your use case is not >> supported. The validators *have* to be only on the 2nd component. >> >> -Andrew >> >> >> On 9/4/07, Suhel Rizvi <[EMAIL PROTECTED]> wrote: >> > >> > I agree with you but unfortunately the customer for whom I'm >> developing the >> > software doesn't, but additionally the problem in itself is >> something we >> > should be able to solve relatively simply I would have thought as >> it may be >> > a valid scenario in other software projects. >> > >> > >From: "Andrew Robinson" <[EMAIL PROTECTED]> >> > >Reply-To: "MyFaces Discussion" <[email protected]> >> > >To: "MyFaces Discussion" <[email protected]> >> > >Subject: Re: [Tomahawk] validateEqual problem for second field >> > >Date: Tue, 4 Sep 2007 10:41:39 -0600 >> > > >> > >Not a solution but a question, >> > > >> > >why have the validate equal on both components, it should only be >> > >necessary to put it on one of the components (like the 2nd one). The >> > >user shouldn't need two messages telling them they screwed up, one >> > >should be necessary :-) >> > > >> > >-Andrew >> > > >> > >On 9/4/07, Suhel Rizvi <[EMAIL PROTECTED]> wrote: >> > > > >> > > > I am using the tomahawk validateEqual tag to check if two (non >> > >mandatory) >> > > > fields on a form are equal to each other but hitting some problems >> > >related >> > > > to the order of the field validations. >> > > > >> > > > In the example below the validation and error message attached >> to the >> > >second >> > > > field works fine. However for the validation on the first field >> it seems >> > >I >> > > > have to submit the form the fields are in twice if the fields >> are equal >> > >- >> > > > the first time it always displays the error message saying they >> are >> > >unequal >> > > > but seems to realize they are equal on second submit. >> > > > >> > > > <h:inputText id="equal" >> > > > value="#{validateForm.equal}" >> > > > required="false"> >> > > > <t:validateEqual for="equa2l" /> >> > > > </h:inputText> >> > > > <h:inputText id="equal2" >> > > > value="#{validateForm.equal2}" >> > > > required="false"> >> > > > <t:validateEqual for="equal" /> >> > > > </h:inputText> >> > > > >> > > > Does anyone know why this is happening or have a solution ? >> > > > >> > > > [I have also tried the sandbox validateCompareTo tag as an >> alternative >> > >with >> > > > similar results.] >> > > > >> > > > _________________________________________________________________ >> > > > Get Pimped! FREE emoticon packs from Windows Live - >> > > > http://www.pimpmylive.co.uk >> > > > >> > > > >> > >> > _________________________________________________________________ >> > Get Pimped! FREE emoticon packs from Windows Live - >> > http://www.pimpmylive.co.uk >> > >> > > > _________________________________________________________________ > The next generation of Hotmail is here! http://www.newhotmail.co.uk > > > __________ NOD32 2501 (20070903) Information __________ > > This message was checked by NOD32 antivirus system. > http://www.eset.com > > >

