Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remote validation not working with command objects #17

Open
pdemilly opened this issue Nov 8, 2012 · 4 comments
Open

remote validation not working with command objects #17

pdemilly opened this issue Nov 8, 2012 · 4 comments

Comments

@pdemilly
Copy link

pdemilly commented Nov 8, 2012

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

                        import org.springframework.beans.factory.config.AutowireCapableBeanFactory

and add this after initiating validatableInstance in the method validate() around line 41
applicationContext.autowireCapableBeanFactory.autowireBeanProperties(validatableInstance,AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false)

  1. command objects don't respond to isAttached

in same method validate() around line 57 replace

          if(validatableInstance.isAttached()) validatableInstance.discard()

by
if(validatableInstance.metaClass.respondsTo(validatableInstance, "isAttached") && validatableInstance.isAttached())
validatableInstance.discard()

Hope that helps

Regards

Pascal

@limcheekin
Copy link
Owner

Hi Pascal,

Thanks for report the issue. Could you clone the project, apply the fix and send me pull request.

Thank you

@pdemilly
Copy link
Author

pdemilly commented Nov 9, 2012

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?

@christopherKwiatkowski
Copy link

@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.

jonroler added a commit to jonroler/jquery-validation-ui that referenced this issue Mar 29, 2013
…/command object in JQueryRemoteValidationController.
@jonroler
Copy link
Contributor

I have now pushed a fix for this problem (pull request #26) which is nearly identical to what Pascal proposed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants