neuland / spring-jade4j

jade4j spring integration
101 stars 23 forks source link

Spring MVC form binding #7

Open gabrielbauman opened 11 years ago

gabrielbauman commented 11 years ago

Hi there,

Spring does some nifty form backing object binding and validation when a controller has a method like this:

public String handleForm(@ModelAttribute @Valid EmployeeForm employeeForm, BindingResult bindingResult)

I'm trying to figure out how to hook into this mechanism from a Jade template. Immediate question: how should my form input tags be named for the above controller method?

Obviously spring-jade4j doesn't have a macro library like that offered by Spring's Freemarker, Velocity, and JSP template resolvers. It seems like one could be easily implemented using Jade mixins.

gabrielbauman commented 11 years ago

I've found that Spring inserts BindingResults instances for each @ModelAttribute into the model after the controller method runs.

The binding result including field values and validation errors can be found in the model with the key BindingResult.MODEL_KEY_PREFIX + objectName .

For the above handleForm method, that would be "org.springframework.validation.BindingResult.employeeForm".

I'm working on a small Jade mixin library to make working with this easier.

ytoh commented 11 years ago

Hi @gabrielbauman any luck with the mixin library?

I am working on something similar for our project.

/Martin