Re: [T5.1] select with required validation
Thank you all for your answers. the User object is valid, because everything i need when submitting the form is userID to save the data. that is why i'm setting selected id to constructed object. why toString() returns "". Because it was used to display formatted output of surname and name somewhere in grid or beandisplay. it's not correct, i know, but it saved me some time in past when i was testing tapestry functionality. i will not bother anyway with custom validator especially now, when i know the reason. i just abandoned using toString as the source for meaningful information. but i still wanted to know, if it is undesired behavior, to check object.toString for empty. you confirmed this (although Howard's opinion is decisive) -- View this message in context: http://old.nabble.com/-T5.1--select-with-required-validation-tp28461777p28470182.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: [T5.1] select with required validation
On Wed, 05 May 2010 18:48:47 -0300, Josh Canfield wrote: Your problem is definitely with the Required validator, although it's a little suspect that a valid User.toString() returns an empty string That's strange for me too. I'm not sure why value.toString() is called. The class is documented as "A validator that enforces that the value is not null and not the empty string." Perhaps it should be checking that value is an instance of String before testing for blank? It looks like a slight bug for me. A workaround (way around) would be to create your own implementation of the Required validator. Perhaps a NotNull validator that only checks for null? Maybe one already exists out there but I didn't look. Implementing one is quite easy. -- 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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: [T5.1] select with required validation
Your problem is definitely with the Required validator, although it's a little suspect that a valid User.toString() returns an empty string or that you are building incomplete entities in the ValueEncoder. In my opinion the validator should not be returning an error. public void validate(Field field, Void constraintValue, MessageFormatter formatter, Object value) throws ValidationException { if (value == null || InternalUtils.isBlank(value.toString())) throw new ValidationException(buildMessage(formatter, field)); } I'm not sure why value.toString() is called. The class is documented as "A validator that enforces that the value is not null and not the empty string." Perhaps it should be checking that value is an instance of String before testing for blank? A workaround (way around) would be to create your own implementation of the Required validator. Perhaps a NotNull validator that only checks for null? Maybe one already exists out there but I didn't look. Josh On Wed, May 5, 2010 at 1:22 PM, paha wrote: > > > Thiago H. de Paula Figueiredo wrote: >> >> You should provide your own ValueEncoder that doesn't rely on toString(). >> > well if you've read my first post, you could see that my ValueEncoder > doesn't rely on toString(). It is rather Tapestry Validator, that runs > toString on User object and assumes it is null, when it is not. > > > Thiago H. de Paula Figueiredo wrote: >> >>> if i set either name or surname property to some dummy value, things >>> work again. Is it expected behavior? >> >> Tapestry's Required validator treats empty string as null. >> > the problem is, the object returned from valueencoder is not a string and it > is not empty. i don't know the internals, i cannot criticize. imho objects > returned from valuencoder schould be only checked against null unless they > are really strings. > > unfortunately, there is no hint in ValueEncoder, that a toValue method must > return an object , whose toString() method returns not null. in contrary it > states "the corresponding entity, or null if not found". in my case User > instance with correct id is an corresponding entity, but it is treated as > not found because of toString > -- > View this message in context: > http://old.nabble.com/-T5.1--select-with-required-validation-tp28461777p28466005.html > Sent from the Tapestry - User mailing list archive at Nabble.com. > > > - > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > > -- -- http://www.bodylabgym.com - a private, by appointment only, one-on-one health and fitness facility. -- http://www.ectransition.com - Quality Electronic Cigarettes at a reasonable price! -- TheDailyTube.com. Sign up and get the best new videos on the internet delivered fresh to your inbox. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: [T5.1] select with required validation
Thiago H. de Paula Figueiredo wrote: > > You should provide your own ValueEncoder that doesn't rely on toString(). > well if you've read my first post, you could see that my ValueEncoder doesn't rely on toString(). It is rather Tapestry Validator, that runs toString on User object and assumes it is null, when it is not. Thiago H. de Paula Figueiredo wrote: > >> if i set either name or surname property to some dummy value, things >> work again. Is it expected behavior? > > Tapestry's Required validator treats empty string as null. > the problem is, the object returned from valueencoder is not a string and it is not empty. i don't know the internals, i cannot criticize. imho objects returned from valuencoder schould be only checked against null unless they are really strings. unfortunately, there is no hint in ValueEncoder, that a toValue method must return an object , whose toString() method returns not null. in contrary it states "the corresponding entity, or null if not found". in my case User instance with correct id is an corresponding entity, but it is treated as not found because of toString -- View this message in context: http://old.nabble.com/-T5.1--select-with-required-validation-tp28461777p28466005.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: [T5.1] select with required validation
On Wed, 05 May 2010 12:45:20 -0300, paha wrote: thank you, you gave me some idea and i found a reason. my User class overrides toString returning name+surname. when the valueencoder runs toObject method, a User-Object with only id set gets created. so the toString of this object returns "" and the object is considered empty even if it is not null!!! You should provide your own ValueEncoder that doesn't rely on toString(). if i set either name or surname property to some dummy value, things work again. Is it expected behavior? Tapestry's Required validator treats empty string as null. -- 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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: [T5.1] select with required validation
Thiago H. de Paula Figueiredo wrote: > > Tapestry form field components don't update the edited property when a > validation error ocurrs > thank you, you gave me some idea and i found a reason. my User class overrides toString returning name+surname. when the valueencoder runs toObject method, a User-Object with only id set gets created. so the toString of this object returns "" and the object is considered empty even if it is not null!!! if i set either name or surname property to some dummy value, things work again. Is it expected behavior? For me this is at least surprising. there must be a check somewhere like obj == null || isEmpty(obj.toString()) . of course i will check toString to never return empty string -- View this message in context: http://old.nabble.com/-T5.1--select-with-required-validation-tp28461777p28462691.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: [T5.1] select with required validation
On Wed, 05 May 2010 12:01:26 -0300, paha wrote: no, it is not null. as i said, the properly selected value gets never submitted or doesn't survive validation (don't know what is really going on> and in which order) - but encoder gets correct value and returns correct object. and as soon as i remove validation, everything works like a charm. Tapestry form field components don't update the edited property when a validation error ocurrs. -- 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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: [T5.1] select with required validation
Pablo dos Reis wrote: > > Try verify if the 'user' is null in the toClient method . > no, it is not null. as i said, the properly selected value gets never submitted or doesn't survive validation (don't know what is really going on and in which order) - but encoder gets correct value and returns correct object. and as soon as i remove validation, everything works like a charm. -- View this message in context: http://old.nabble.com/-T5.1--select-with-required-validation-tp28461777p28462190.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: [T5.1] select with required validation
Try verify if the 'user' is null in the toClient method . 2010/5/5 paha > > Hi, it must be again some misunderstanding from my side. I have a form and > select > > encoder="supervisorEncoder" model="supervisorModel" > blankOption="always"/> > > > in OnSubmit i see that all other field values of the form (and also some > selects but with Enum as Model) get applied to company object except for > this select. AS SOON AS i remove > validate="required" it's get applied too. Sure i can do server-side > validation to check if the object is not set, but is it an expected > behavior? > > the supervisorEncoder is defined as > > public class UserValueEncoder implements ValueEncoder { >@Override >public String toClient(Object user) { >return ((User) user).getId().toString(); >} > >@Override >public Object toValue(String id) { >return StringUtils.isNotBlank(id) >? new User().setId(Integer.parseInt(id)) >: null; >} > } > > again, if validate="required" is omitted, everything works as expected. but > if not, selected value seems to never got submitted firing "required" error > message > -- > View this message in context: > http://old.nabble.com/-T5.1--select-with-required-validation-tp28461777p28461777.html > Sent from the Tapestry - User mailing list archive at Nabble.com. > > > - > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > > -- Pablo Henrique dos Reis
[T5.1] select with required validation
Hi, it must be again some misunderstanding from my side. I have a form and select in OnSubmit i see that all other field values of the form (and also some selects but with Enum as Model) get applied to company object except for this select. AS SOON AS i remove validate="required" it's get applied too. Sure i can do server-side validation to check if the object is not set, but is it an expected behavior? the supervisorEncoder is defined as public class UserValueEncoder implements ValueEncoder { @Override public String toClient(Object user) { return ((User) user).getId().toString(); } @Override public Object toValue(String id) { return StringUtils.isNotBlank(id) ? new User().setId(Integer.parseInt(id)) : null; } } again, if validate="required" is omitted, everything works as expected. but if not, selected value seems to never got submitted firing "required" error message -- View this message in context: http://old.nabble.com/-T5.1--select-with-required-validation-tp28461777p28461777.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org