You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by hese <10...@gmail.com> on 2011/06/29 20:35:43 UTC
how to dynamically turn "t:validate" off
I have a select control for which I want to set the t:validate attribute
dynamically. For some cases when the form loads I dont want validation on
the control.
So in in the tml definition of the control I have -
t:validate="${validate}"
and in my java class I have
public String getValidate() {
return programsGroup.getPrograms().size() == 1 ? "validate" : "";
}
What should I give instead of "" to dynamically set validation off? (Tried
to return a null too, but getting an exception)
Thanks
--
View this message in context: http://tapestry.1045711.n5.nabble.com/how-to-dynamically-turn-t-validate-off-tp4536095p4536095.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: how to dynamically turn "t:validate" off
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 29 Jun 2011 15:35:43 -0300, hese <10...@gmail.com> wrote:
> I have a select control for which I want to set the t:validate attribute
> dynamically. For some cases when the form loads I dont want validation
> on the control.
Hi!
> So in in the tml definition of the control I have -
> t:validate="${validate}"
The type of the validate parameter is FieldValidator, so this won't work
no matter what you pass to it. Search the list for FieldValidator and
you'll find some answers. ;)
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: how to dynamically turn "t:validate" off
Posted by Robert Zeigler <ro...@roxanemy.com>.
There's not really anything to post? It's just a bunch of empty methods...
new FieldValidator() {
public boolean isRequired() { return false; }
public void render(MarkupWriter writer) {}
public void validate(Object value) {}
}
Since the code does nothing, it's possible to create a single instance of FieldValidator and use it anywhere you need it.
Robert
On Jun 29, 2011, at 6/292:45 PM , hese wrote:
>
> ok, so I tried this -
>
> public FieldValidator getNameFieldValidator() {
> String validationString = programsGroup.getPrograms().size() == 1 ?
> "required" : "none";
> Field f = (Field) componentResources.getEmbeddedComponent("name");
> return fieldValidatorSource.createValidator(f, validationString,
> null);
> }
>
> (seeing an example in another post in this list)
>
> But getting the error "Unknown validator type 'none'. Configured validators
> are email, max, maxlength, min, minlength, regexp, required."
>
> So looks like I have to write my own, no-op validator as robert suggested.
> Or is there something i am missing?
>
> Robert - would appreciate if you can post your no-op validator.
>
> Thanks.
>
>
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/how-to-dynamically-turn-t-validate-off-tp4536095p4536381.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: how to dynamically turn "t:validate" off
Posted by hese <10...@gmail.com>.
@Thiago - Tried using null instead of "none" and it gave the error
"Parameter validatorType was null or contained only whitespace".
@Robert - thanks for the code. It worked great.
I've pasted my code below....but I am having to have a separate getValidator
method for each of my components since the createValidator() method requires
a 'Field'. Not sure if there is a generic way to do this.
private FieldValidator noopValidator = new FieldValidator() {
public boolean isRequired() {return false;}
public void render(MarkupWriter writer) {}
public void validate(Object value) {}
};
public FieldValidator getNameValidator() {
return getValidator("name");
}
public FieldValidator getCampaignIdValidator() {
return getValidator("campaignId");
}
public FieldValidator getAdvertiserIdValidator() {
return getValidator("advertiserId");
}
public FieldValidator getValidator(String componentId) {
if(programsGroup.getPrograms().size() == 1) {
Field f = (Field)
componentResources.getEmbeddedComponent(componentId);
return fieldValidatorSource.createValidator(f, "required", null);
}
return noopValidator;
}
--
View this message in context: http://tapestry.1045711.n5.nabble.com/how-to-dynamically-turn-t-validate-off-tp4536095p4536543.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: how to dynamically turn "t:validate" off
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 29 Jun 2011 16:45:17 -0300, hese <10...@gmail.com> wrote:
> ok, so I tried this -
>
> public FieldValidator getNameFieldValidator() {
> String validationString = programsGroup.getPrograms().size() == 1 ?
> "required" : "none";
> Field f = (Field)
> componentResources.getEmbeddedComponent("name");
> return fieldValidatorSource.createValidator(f, validationString,
> null);
> }
There's no validator named 'none'. Try returning null instead.
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: how to dynamically turn "t:validate" off
Posted by hese <10...@gmail.com>.
ok, so I tried this -
public FieldValidator getNameFieldValidator() {
String validationString = programsGroup.getPrograms().size() == 1 ?
"required" : "none";
Field f = (Field) componentResources.getEmbeddedComponent("name");
return fieldValidatorSource.createValidator(f, validationString,
null);
}
(seeing an example in another post in this list)
But getting the error "Unknown validator type 'none'. Configured validators
are email, max, maxlength, min, minlength, regexp, required."
So looks like I have to write my own, no-op validator as robert suggested.
Or is there something i am missing?
Robert - would appreciate if you can post your no-op validator.
Thanks.
--
View this message in context: http://tapestry.1045711.n5.nabble.com/how-to-dynamically-turn-t-validate-off-tp4536095p4536381.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: how to dynamically turn "t:validate" off
Posted by Robert Zeigler <ro...@roxanemy.com>.
What I typically do in this case is to have a "noop validator". isRequired returns false, and the render and validate methods are no-op.
It might make sense for tapestry to provide a validator named "noop" or some such for this use-case... I know I've encountered it a fair bit.
On Jun 29, 2011, at 6/291:35 PM , hese wrote:
>
> I have a select control for which I want to set the t:validate attribute
> dynamically. For some cases when the form loads I dont want validation on
> the control.
>
> So in in the tml definition of the control I have -
>
> t:validate="${validate}"
>
> and in my java class I have
>
> public String getValidate() {
> return programsGroup.getPrograms().size() == 1 ? "validate" : "";
> }
>
> What should I give instead of "" to dynamically set validation off? (Tried
> to return a null too, but getting an exception)
>
> Thanks
>
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/how-to-dynamically-turn-t-validate-off-tp4536095p4536095.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org