Open pdemilly opened 12 years ago
Hi Pascal,
Thanks for report the issue. Could you clone the project, apply the fix and send me pull request.
Thank you
OK! I did. Made the change ready to push them. However I have a question. in validate of JQueryRemoveValidationController param doesn't have all the fields value of the form. Therefore the binding doesn't happen which mean I cannot have a custom validator that check the value of another field. (ie password check). Where should I look to add this?
@pdemilly I just wanted to offer a suggestion, even though this thread is 3 months old and it is likely that you have already addressed the issue of not having a command object that is fully populated. I added an additional property to the data object created by the JQueryValidationService.createRemoteJavaScriptConstraints method called serializedData:
String remoteJavaScriptConstraints = "\t${constraintName.equals('unique') || constraintName.equals('validator')?constraintName:'custom'}: {\n" +
"\turl: '${contextPath}/validation/validate',\n" +
"\ttype: 'post',\n" +
"\tdata: {\n" +
"\t\tvalidatableClass: '${validatableClassName}',\n" +
"\t\tproperty: '${propertyName}',\n" +
"\t\tserializedData: function() { return myForm.serialize() }\n"
As the variable name of the form is always myForm you may serialize the entire form and then use the values from the params.serializedData in the remote validation controller. This is somewhat of an un-elegant solution, but it gets the values up to the validation controller and we use them as necessary to bind to the Validateable class currently under remote validation.
I have now pushed a fix for this problem (pull request #26) which is nearly identical to what Pascal proposed.
When using command objects a few things don't work correctly.
1) auto wiring.
when a custom validator needs to access a service defined in the command object (same might be for domain object), the service instance variable has not been injected before calling the custom validator.
in JQueryRemoteValidatorController.groovy
and add this after initiating validatableInstance in the method validate() around line 41 applicationContext.autowireCapableBeanFactory.autowireBeanProperties(validatableInstance,AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false)
2) command objects don't respond to isAttached
in same method validate() around line 57 replace
by if(validatableInstance.metaClass.respondsTo(validatableInstance, "isAttached") && validatableInstance.isAttached()) validatableInstance.discard()
Hope that helps
Regards
Pascal