Re: [t5] Validator question
Actually, I was able to get this done. I had to contributeValidationMessagesSource to get the messages. And to get to the current page component from within the Validator, I was able to do this: public static void contributeFieldValidatorSource (MappedConfiguration configuration, @InjectService ("ComponentSource")ComponentSource componentSource, @InjectService ("Request")Request request ) { configuration.add("confirm", new Confirm(componentSource, request)); } and then: String[] pathComponents = request.getPath().split("/"); String pageComponent = pathComponents[pathComponents.length - 1]; String[] pageComponents = pageComponent.split("\\."); Component page = componentSource.getPage(pageComponents[0]); but this seems a little fragile. Is there a better way? I do see what you mean though - there is nowhere to attach a piece of javascript to accompany this validator, so it just goes into my own global library. But I'm pretty happy overall with this solution. J On 25-Mar-08, at 2:13 PM, Julian Wood wrote: Ok no worries. On a related note, where do you put the messages file for a custom validator? In the example below, which looks for a key called 'confirm', I have tried Confirm.properties (in same package as validator called Confirm.java), Signup.properties (the page using the validator) and app.properties. The latter two of course have verifiably working messages. I always get a [[missing key: confirm]] though. Back to my validator question, I couldn't find the JIRA issue you were referring to. BTW, the client side of this type of a validator works quite nicely. In .java: @Validate("required") public String getPassword() { return password; } @Validate("required,confirm=password") public String getConfirmPassword() { return confirmPassword; } On the .tml: Object.extend(Tapestry.Validator, { confirm: function(field, message, constraint) { Tapestry.addValidator(field, true, function(value, event) { var confirmationSourceField = $(constraint); if (confirmationSourceField == null) { console.error("No such field: " + constraint); return; } else if (value != confirmationSourceField.value) { event.recordError(message); } }); } }) And in Confirm.java (the validator): public void render(Field field, String sourceFieldId, MessageFormatter formatter, MarkupWriter markupWriter, FormSupport formSupport) { formSupport.addValidation(field, "confirm", buildMessage (formatter, field), sourceFieldId); } J On Mar 25, 2008, at 12:27 PM, Howard Lewis Ship wrote: Sorry, those APIs are not in place yet. I have JIRA issue add optional validators, which is a loose, general term for what you are aiming for ("password is required if userName is given"). I think some relationships may not be expressable using the @Validate annotation, i.e., the string representation; I'm thinking there will be a kind of JavaScript template object that will be used to generate some kinds of JavaScript. Things have slowed down on 5.0 for a moment, while I work on an urgent client project (in Tapestry 5). On Tue, Mar 25, 2008 at 11:08 AM, Julian Wood <[EMAIL PROTECTED]> wrote: Not possible? Sometimes a validator needs to look at input from another field to see if it is valid (ie password/confirmPassword). I know it's easy to do in onValidateForm, but I'd like to see how to do it in a nice modular Validator. I'm looking for something like: public void validate(Field field, String sourceFieldId, MessageFormatter formatter, Object value) throws ValidationException { Component page = ((AbstractField) field)._resources.getPage(); try { Method getter = page.getClass().getDeclaredMethod(getMethodName(sourceFieldId)); String sourceValue = (String) getter.invoke(page); if (value == null || !value.toString().equals (sourceValue)) throw new ValidationException(buildMessage (formatter, field)); } catch (Exception e) { log.error("No public getter field in page for: " + sourceFieldId); } } but can't do that (the only problem being the private _resources). How can that be done in a Validator? I can't inject anything. I don't actually need to make my own field which exposes the ComponentResources, do I? Thanks. J On Mar 24, 2008, at 5:17 PM, Julian Wood wrote: How can you get access to an arbitrary Field from inside a Validator, given its id? In t4 it was relatively easy to grab the form and from there grab a field. Thanks, J -
Re: [t5] Validator question
Ok no worries. On a related note, where do you put the messages file for a custom validator? In the example below, which looks for a key called 'confirm', I have tried Confirm.properties (in same package as validator called Confirm.java), Signup.properties (the page using the validator) and app.properties. The latter two of course have verifiably working messages. I always get a [[missing key: confirm]] though. Back to my validator question, I couldn't find the JIRA issue you were referring to. BTW, the client side of this type of a validator works quite nicely. In .java: @Validate("required") public String getPassword() { return password; } @Validate("required,confirm=password") public String getConfirmPassword() { return confirmPassword; } On the .tml: Object.extend(Tapestry.Validator, { confirm: function(field, message, constraint) { Tapestry.addValidator(field, true, function(value, event) { var confirmationSourceField = $(constraint); if (confirmationSourceField == null) { console.error("No such field: " + constraint); return; } else if (value != confirmationSourceField.value) { event.recordError(message); } }); } }) And in Confirm.java (the validator): public void render(Field field, String sourceFieldId, MessageFormatter formatter, MarkupWriter markupWriter, FormSupport formSupport) { formSupport.addValidation(field, "confirm", buildMessage(formatter, field), sourceFieldId); } J On Mar 25, 2008, at 12:27 PM, Howard Lewis Ship wrote: Sorry, those APIs are not in place yet. I have JIRA issue add optional validators, which is a loose, general term for what you are aiming for ("password is required if userName is given"). I think some relationships may not be expressable using the @Validate annotation, i.e., the string representation; I'm thinking there will be a kind of JavaScript template object that will be used to generate some kinds of JavaScript. Things have slowed down on 5.0 for a moment, while I work on an urgent client project (in Tapestry 5). On Tue, Mar 25, 2008 at 11:08 AM, Julian Wood <[EMAIL PROTECTED]> wrote: Not possible? Sometimes a validator needs to look at input from another field to see if it is valid (ie password/confirmPassword). I know it's easy to do in onValidateForm, but I'd like to see how to do it in a nice modular Validator. I'm looking for something like: public void validate(Field field, String sourceFieldId, MessageFormatter formatter, Object value) throws ValidationException { Component page = ((AbstractField) field)._resources.getPage(); try { Method getter = page.getClass().getDeclaredMethod(getMethodName(sourceFieldId)); String sourceValue = (String) getter.invoke(page); if (value == null || ! value.toString().equals(sourceValue)) throw new ValidationException(buildMessage(formatter, field)); } catch (Exception e) { log.error("No public getter field in page for: " + sourceFieldId); } } but can't do that (the only problem being the private _resources). How can that be done in a Validator? I can't inject anything. I don't actually need to make my own field which exposes the ComponentResources, do I? Thanks. J On Mar 24, 2008, at 5:17 PM, Julian Wood wrote: How can you get access to an arbitrary Field from inside a Validator, given its id? In t4 it was relatively easy to grab the form and from there grab a field. Thanks, J - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Howard M. Lewis Ship Creator Apache Tapestry and Apache HiveMind - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [t5] Validator question
Sorry, those APIs are not in place yet. I have JIRA issue add optional validators, which is a loose, general term for what you are aiming for ("password is required if userName is given"). I think some relationships may not be expressable using the @Validate annotation, i.e., the string representation; I'm thinking there will be a kind of JavaScript template object that will be used to generate some kinds of JavaScript. Things have slowed down on 5.0 for a moment, while I work on an urgent client project (in Tapestry 5). On Tue, Mar 25, 2008 at 11:08 AM, Julian Wood <[EMAIL PROTECTED]> wrote: > Not possible? > > Sometimes a validator needs to look at input from another field to see > if it is valid (ie password/confirmPassword). I know it's easy to do > in onValidateForm, but I'd like to see how to do it in a nice modular > Validator. I'm looking for something like: > > public void validate(Field field, String sourceFieldId, > MessageFormatter formatter, Object value) throws ValidationException { > Component page = ((AbstractField) field)._resources.getPage(); > try { > Method getter = > page.getClass().getDeclaredMethod(getMethodName(sourceFieldId)); > String sourceValue = (String) getter.invoke(page); > if (value == null || !value.toString().equals(sourceValue)) > throw new ValidationException(buildMessage(formatter, > field)); > } catch (Exception e) { > log.error("No public getter field in page for: " + > sourceFieldId); > } > } > > > but can't do that (the only problem being the private _resources). How > can that be done in a Validator? I can't inject anything. I don't > actually need to make my own field which exposes the > ComponentResources, do I? > > Thanks. > > J > > > > > > On Mar 24, 2008, at 5:17 PM, Julian Wood wrote: > > > How can you get access to an arbitrary Field from inside a > > Validator, given its id? In t4 it was relatively easy to grab the > > form and from there grab a field. > > > > Thanks, > > > > J > > > > - > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- Howard M. Lewis Ship Creator Apache Tapestry and Apache HiveMind - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [t5] Validator question
Not possible? Sometimes a validator needs to look at input from another field to see if it is valid (ie password/confirmPassword). I know it's easy to do in onValidateForm, but I'd like to see how to do it in a nice modular Validator. I'm looking for something like: public void validate(Field field, String sourceFieldId, MessageFormatter formatter, Object value) throws ValidationException { Component page = ((AbstractField) field)._resources.getPage(); try { Method getter = page.getClass().getDeclaredMethod(getMethodName(sourceFieldId)); String sourceValue = (String) getter.invoke(page); if (value == null || !value.toString().equals(sourceValue)) throw new ValidationException(buildMessage(formatter, field)); } catch (Exception e) { log.error("No public getter field in page for: " + sourceFieldId); } } but can't do that (the only problem being the private _resources). How can that be done in a Validator? I can't inject anything. I don't actually need to make my own field which exposes the ComponentResources, do I? Thanks. J On Mar 24, 2008, at 5:17 PM, Julian Wood wrote: How can you get access to an arbitrary Field from inside a Validator, given its id? In t4 it was relatively easy to grab the form and from there grab a field. Thanks, J - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: T5 validator question
I've already found my answer in the magical @Inject private FieldValidatorSource _fieldValidatorSource; with the _fieldValidatorSource.createValidator(this, "myRegistredValidator", null); everything works fine ! Bye -Rick Riccardo Ruffilli wrote: > > Hi All, > > I'm working on validator class in my t5 application, and I've defined my > own validator > that implements Validator I've registred them like t5 > contribution in > my AppModule.java and then I can use them easily in my tag with the > parameter validator="validate:myownvalidator". > > With the validate prefix I've noticed that t5 obtain a FieldValidatorImpl > that contains myvalidator > instance like _validate internal property. > I'd like to modelize my component to make it working without any template > explicit parameter > using a model class that wrap all my tag parameter in that way > > > > instead of > > > > and at rendering time My component get all that values from the model > specified. > That works fine exept for validator parameter because I need to obtain > myown FieldValidatorImpl > instance. > > Any ideas about that ? > > Many thanks in advance. > > -Rick > > > > -- View this message in context: http://www.nabble.com/T5-validator-question-tp16001442p16001764.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]