You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by jp...@mchsi.com on 2009/07/24 22:19:52 UTC

Dynamically set isRequired() field on a componentn

I'm trying to dynamically set the isRequired() field for a component, but not sure how to do so. For example, in the following example, I'd like to set the streetAddress component to be required if the pin1 field has data entered for it. My first attempt (which doesn't work since it's binding statically) is as follows:

 PINTextField pin1 = new PINTextField("pin1",
                new PropertyModel(propertyUse, "otherPropertyPin1"));
        pin1.add(StringValidator.maximumLength(20));
        commonQuestionsWMC.add(pin1);

streetAddress1.add(StringValidator.maximumLength(35)).setRequired(isCommonQuestionsVisible);
        streetAddress1.setRequired(StringUtils.isNotBlank(pin1.getValue()));
        commonQuestionsWMC.add(streetAddress1);

RE: Dynamically set isRequired() field on a componentn

Posted by Joel Barciauskas <JB...@nexaweb.com>.
What you are looking for is something like this:

final PINTextField pin1 = new PINTextField("pin1",
                new PropertyModel(propertyUse, "otherPropertyPin1"));
        pin1.add(StringValidator.maximumLength(20));
        commonQuestionsWMC.add(pin1);
streetAddress1 = new TextField("streetAddress") {
                                                public boolean checkRequired()
                                                {
                                                                return isRequired() && isEnabled() && pin1.getInput() != null && pin1.getInput().trim().length() >0;
                                                }
                                }.setRequired(true);

From: jpalmer1026@mchsi.com [mailto:jpalmer1026@mchsi.com]
Sent: Friday, July 24, 2009 10:20 PM
To: users@wicket.apache.org
Subject: Dynamically set isRequired() field on a componentn

I'm trying to dynamically set the isRequired() field for a component, but not sure how to do so. For example, in the following example, I'd like to set the streetAddress component to be required if the pin1 field has data entered for it. My first attempt (which doesn't work since it's binding statically) is as follows:

 PINTextField pin1 = new PINTextField("pin1",
                new PropertyModel(propertyUse, "otherPropertyPin1"));
        pin1.add(StringValidator.maximumLength(20));
        commonQuestionsWMC.add(pin1);

streetAddress1.add(StringValidator.maximumLength(35)).setRequired(isCommonQuestionsVisible);
        streetAddress1.setRequired(StringUtils.isNotBlank(pin1.getValue()));
        commonQuestionsWMC.add(streetAddress1);