cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

customizing address validation

0 Likes
1,147

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?

Accepted Solutions (0)

Answers (2)

Answers (2)

0 Likes
former_member704915
Participant
0 Likes

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 🙂

0 Likes

Hello Abhijit, Thanks for your prompt reply. I do not quite understand it. The account page controller is generated OOTB. I just changed the addressValidator to my customAddressValidator.

Can you please assist with the steps if i want to override the addressForm and Validator.

former_member704915
Participant
0 Likes

I have edited the answer and have provided the steps. There is no need to define a spring.xml file or edit the project.properties file. Please try and let me know.

former_member704915
Participant
0 Likes

Hi : Did this work for you?

0 Likes

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

former_member704915
Participant
0 Likes

Did you forget to annotate the custom address validator class with component anotation? Did you use the same name in resource annotation in controller? This worked for me in my local setup. Please check. You are missing some bean definitions.

0 Likes

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.