Announcement Announcement Module
Collapse
No announcement yet.
configure propertyEditors(propertyEditorRegistrar) in controller Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • configure propertyEditors(propertyEditorRegistrar) in controller

    Hi all,

    Can anybody tell me how to configure the propertyEditorRegistrar for a controller which is much simpler in case of webflow

    like the following code(in webflow)

    <property name="propertyEditorRegistrar">
    <bean class="aero.sita.bag.wtw.web.propertyeditor.WtwPro pertyEditorRegistrar"/>
    </property>

    Similar type of configuration required in controller please help me.

    Thanks !!

  • #2
    Something like this:

    Code:
     public class ClinicBindingInitializer implements WebBindingInitializer {
     	public void initBinder(WebDataBinder binder, WebRequest request) {
     		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
     		dateFormat.setLenient(false);
     		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
     		binder.registerCustomEditor(String.class, new StringTrimmerEditor(false));
     		binder.registerCustomEditor(PetType.class, new PetTypeEditor());
     	}
      }
    Code:
    public class PetTypeEditor extends PropertyEditorSupport {
     	@Override
     	public void setAsText(String text) throws IllegalArgumentException {
     		List<PetType> petTypes = Pet.findAll(Arg.asc("name"));
     
     		for (PetType type : petTypes) {
     			if (type.getName().equals(text)) {
     				setValue(type);
     			}
     		}
     	}
     }
    Code:
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
     		<property name="webBindingInitializer">
     			<bean class="org.jraptor.petclinic.web.ClinicBindingInitializer" />
     		</property>
    </bean>
    Cheers

    G

    Comment


    • #3
      I want it when the response is given back to the jsp from the controller

      Hi Goran,

      Thanks for your reply .


      If we configure using initBinder() whenever we submit the request before binding to the form object it is intercepted by the property Editors we register and set it in form object.

      This is fine.

      But when the response is given from the controller (that response object may be different one, not the same form object) that response object should also get converted using the property editors to a specific format. will the initBinder() do this also ?

      Please help me.

      Thanks dude.

      Comment

      Working...
      X