0

I am upgrading the spring framework from very old version to 5.3.9. In the current Spring configuration, I have below validation framework included. In the new spring, I will not have the below info in the configuration file. How can I replace with validation in the new Spring framework ?

<bean id="editAdmin" class="abc.controller.EditAdminController">
      <property name="sessionForm"><value>true</value></property>
      <property name="synchronizeOnSession"><value>true</value></property>
      <property name="commandName"><value>AdminClass</value></property>
      <property name="commandClass"><value>abc.bean.AdminClass</value></property>
      <property name="formView"><value>Admin</value></property>
      <property name="successView"><value>view_admin.html</value></property>
      **<property name="validator"><ref bean="adminValidator"/></property>**
      <property name="dao"><ref bean="adminDAO"/></property>
    </bean>

How do I invoke validation in the controller using new spring version ?

I found below sample online. I think it will work but haven't tried yet.

@RequestMapping(value = "/saveBasicInfoStep1", method = RequestMethod.POST) public String saveBasicInfoStep1(
@Validated(BasicInfo.class) @ModelAttribute("useraccount") UserAccount useraccount, BindingResult result, ModelMap model) { if (result.hasErrors()) { return "error"; } return "success"; }

Thanks!

3
  • I would revert to Spring 5.3 and migrate first to annotation based controllers, then do the upgrade. This is code belonging to the SimpleFormController was has long been deprecated/superseded with annotation based controllers. So first migrate then upgrade. Commented Aug 2, 2023 at 18:16
  • @Denum - My question is specifically about using validations in latest framework. Commented Aug 2, 2023 at 19:31
  • Use @Valid on the @MOdelAttribute and you can setup the databinder (in an @InitBinder annotated method) with the existing validator. If that was your question it was poorly worded. Or you can try to rewrite your validation with annotations on the object. Commented Aug 3, 2023 at 5:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.