on ‎2019 Feb 18 11:35 AM
I am trying to create custom address validation, to not validate postalcode and validate for phone and town.
In an attempt to do this I did the below In my custom folder in the storefront i added a spring file and in project.properties i made it reference that file. In that file i added the an alias beans to extend the address validator . I also created a new addressForm and the custom validator validates for this address form. In accountpagecontroller, i replaced the AddressValidator by my custom validator
Did i do the steps correctly? Now i am getting the below error
Bean property 'validators' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Request clarification before answering.
here is the answer if anyone needs it
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Edit: Please follow the below steps.
Create a java class CustomAddressFormValidator.java in custom--storefront extension. Implement Validator (org.springframework.validation.Validator) and implement the methods as per your requirement. Annotate the class with @Component("customAddressFormValidator")
Now, in your custom -- accountpagecontroller, comment out the address validator wired bean and declare your own bean
@Resource(name = "customAddressFormValidator") private CustomAddressFormValidator addressValidator;
and you are done.
I have tried this and it works. Cheers 🙂
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks a lot I tried that before and again yesterday and both times i got the same error
ERROR [localhost-startStop-2] [ContextLoader] Context initialization failed INFO | jvm 1 | main | 2019/02/19 10:03:44.653 | org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountPageController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'customAddressValidator' available
The validator has the annotation set and it is the same called by the accountPageController class.
I made a new addressForm called customAddressForm to make @NotNull(message = "{address.phone.invalid}") and remove the NotNull before the postalcode. My customAddressValidator validates this customAddressForm.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.