0

I have specific requirement that for certain form in my application, should be saved in capital letter in the database due to compatibility with legacy system. Looking thru the various solution, I found two feature in Spring Web-MVC which can help in achieving this:

  1. Spring Converter SPI and register it using WebMVC Configuration
  2. Custom PropertyEditor and attach it using WebDataBinder API.

First approach converts everything to uppercase, as it is registered at the application level and I want to restrict it to certain form only.

Second approach can be applied to hand picked controller.

Both of them works. However for second approach, I dont want my custom PropertyEditor to be called during rendering phase. It needs to be invoked only when form is getting submitted. And I am looking for a solution which can address it.

Just to be sure, solution need not stick to one of the above mentioned approach. Also, I want to avoid JavaScript listeners on Input field to convert everything in the capital letters, as I dont think that would be rite thing to do.

Gaurav Daga
  • 303
  • 2
  • 9
  • The editor will always be called on both steps, however you would only need to convert in the `setAsText` method if you only want to convert it on the submit. Or simply do it in your business layer if it is that important, just convert to uppercase before saving. (and use `text-transform: uppercase;` as css styling on the input element.). – M. Deinum Aug 11 '15 at 05:43
  • `text-transform: uppercase;` is look only thing as when form is submitted, it gets submitted as it was typed. – Gaurav Daga Aug 12 '15 at 01:21
  • Coming back to `setAsText`, I have provided implementation for this only method in my custom property editor but it is still getting called during render phase. ( If I put a debugger, execution stops at it). I dont want it to be called during render phase, is there a way to do it? – Gaurav Daga Aug 12 '15 at 02:16
  • 1
    Regarding `text-transform:` hence my suggestion to uppercase it in your service layer *together* with `text-transform:` in the front-end!. Unless you are going to write your own tag library and data binding there is no way to prevent the current flow. As mentioned I strongly suggest uppercasing it in your business layer and use the `text-transform;` in the front-end. – M. Deinum Aug 12 '15 at 05:37
  • Yeah, given the situation that make sense. However I was hoping that Spring should provide some configuration point for these custom editor to control the invocation specific to request or response flow. – Gaurav Daga Aug 14 '15 at 00:51

0 Answers0