myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Kienenberger" <mkien...@gmail.com>
Subject Re: many components to one (or more) validation?
Date Thu, 10 Aug 2006 14:07:35 GMT
On 8/10/06, Conway. Fintan (IT Solutions) <Fintan.Conway@esb.ie> wrote:
> If you bind each component in the group to a backing bean, then you
> attach a custom converter to the last control of the group that appears
> on the page (e.g. input field).

Fintan means "validator" and not "converter".  You can see that this
is implied from the latter part of his message.

It's generally more maintainable to use the "hidden text field as the
last field with a validator" method since this leaves both of your
previous components in the same state (local value) and you don't have
to work with a submitted value and a local value at the same time.

However, you'll end up doing most of the work required to create a
validator even if you go this route.    If you start with
validateCompareTo and simply change the validating condition, you'll
probably save time and have a reusable component afterward.




On 8/10/06, Conway. Fintan (IT Solutions) <Fintan.Conway@esb.ie> wrote:
> Hi Joe,
>
> If you bind each component in the group to a backing bean, then you
> attach a custom converter to the last control of the group that appears
> on the page (e.g. input field).
>
>
> public class BackingBean {
> private SelectOneRadio radio;
> private UIInput radioInput;
> ...
> public void validateRadioText(FacesContext context, UIComponent
> component, Object value) {
>    Boolean buttonClicked = ((Boolean)
> radio.getLocalValue()).booleanValue();
>    String radioText = (String)value;      // 1
>
>    if (buttonClicked) {
>       if(!validText(radioText)) {
>          FacesMessage message = ...;
>          throw new ValidatorException(message);
>       }
>    }
> }
>
> Private validText(String textToValidate) {
>    // validate the text here
> }
> ...
> }
>
> NB - The last component will not have its local value set yet (see //1)
>
> In the JSF page set the validator of the last component to this
> validator method
> <t:inputText value=#{...} binding=#{bb.radioInput}
> validator=#{bb.validateRadioText}>
>
> Where bb is set as a managed Backing Bean in faces-config.
>
> Alternatively you could use a hidden field which is the last field on
> the page :
> <h:inputHidden validator="#{bb.validateRadioText}" value="needed"/>
>
> In this case you get the value for radioText (see //1), similarly to how
> it was gotten for buttonClicked, as the local value has been set.
>
> Otherwise you can define your own component similarly to above, if you
> will need this functionality in more than one page.
>
> Regards,
>
> Fintan
>
>
> -----Original Message-----
> From: Joe ersinghaus [mailto:jersingh@nmsu.edu]
> Sent: 10 August 2006 00:35
> To: MyFaces Discussion
> Subject: many components to one (or more) validation?
>
>
> Hello,
>
> Is it possible to have more than one component validated as a group? For
>
> example:  let's say I've have a radio button that when activated, text
> must be entered/validated in that radio button's associated input field?
>
> In other words, only when the radio button is selected, should the input
>
> filed be validated.
>
>
> Thanks,
> Joe
>
>
> * ** *** ** * ** *** ** * ** *** ** *
> 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.
>
> * ** *** ** * ** *** ** * ** *** ** *
>
>

Mime
View raw message