reset password
Author Message
poonam31
Posts: 35
Posted 16:47 Aug 11, 2015 |

Hello Professor,

Using PropertyEditor and < form:select> , <form:checkbox> I could create a form successfully. 

I understood the high level flow. I am not able to understand the exact flow. Could you explain the flow in brief.

Could you please explain how is it able to understand that it is a list in case of chekboxes.

Also, the line 2 in below code, where in application context userPropertyEditor is set/ or what is the meaning of below code:

binder.registerCustomEditor( User.class,

                  (UserPropertyEditor) context.getBean( "userPropertyEditor" ) );

 

 

cysun
Posts: 2935
Posted 17:07 Aug 11, 2015 |

Well, there's not much a workflow in there. Basically all the "value" attributes of HTML form tags are strings. When you bind a property to a form field, if the property is a string or a number, Spring knows how to do it, but if the property is an object, Spring doesn't know how to do it unless you provide a property editor that converts between the object and the string.

HTTP allows multiple request parameters to have the same name. For example, something like ...?a=10&a=20&a=30, or when you use checkboxes (notice that those checkboxes have the same name). Naturally this could be bound to a list or an array property and Spring knows how to do that, too.

The code registers a property editor for User objects. A property editor is an object, which you can create either by calling the constructor, or create it as a Spring bean (review the discussion of the Hello World example in the Spring IoC lecture). For a property editor like the date property editor, we can simply use the constructor, but for the User property editor, we need to create it as a bean because it needs a UserDao which needs to be injected by the framework.

Last edited by cysun at 17:08 Aug 11, 2015.
poonam31
Posts: 35
Posted 17:11 Aug 11, 2015 |

Okay now I understood well.

Thanks Professor :)