Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring MVC no matching editors or conversion strategy found
    primarykey
    data
    text
    <p>I am trying to send custom javascript object (actually, its array of JSON objects) via jquery post request to spring controller. The server-side fails with "bla-bla no matching editors or conversion strategy found" error. It can't convert from string to server-side object. I found <a href="https://stackoverflow.com/questions/2998761/custom-property-editors-do-not-work-for-request-parameters-in-spring-mvc">this</a> and <a href="https://stackoverflow.com/questions/912257/converting-from-string-to-custom-object-for-spring-mvc-form-data-binding">this</a> examples but I can't put it together to make it work. Which methods of PropertyEditor should I override? Does anybody knows link to any example? Thank you.</p> <p>Controller:</p> <pre><code>private class AddressFormEditor extends PropertyEditorSupport { protected Object convertElement(Object element) { String form = ""; if (element instanceof String) form = (String) element; Logger logger = Logger.getLogger(getClass().getName()); logger.warning(form); return form != null ? new AddressForm(form) : null; } } @InitBinder protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { binder.registerCustomEditor(AddressForm.class, new AddressFormEditor()); } @RequestMapping(value = "/save", method = RequestMethod.POST) public ModelAndView saveUser(@ModelAttribute UserForm form, HttpServletResponse response) {...} </code></pre> <p>UserForm:</p> <pre><code>public class UserForm extends BaseForm { private Long id; private String login; private String password; private String confirmPassword; private String type; private String franchise; private String roles; private String firstName; private String lastName; private String salutation; private String position; private String birthDate; private String passportNumber; private String passportIssueBy; private String passportIssueDate; private String passportExpireDate; private String nationality; private AddressForm[] addresses; private String notes; ... } </code></pre> <p>jQuery request:</p> <pre><code>var data = $('#userForm').serializeObject(); data.addresses = addresses; $.ajax({ traditional: true, type: 'POST', url: url + 'save', data: data, success: function(response) { if (response) { initializeUser(response); hideWait(); } else { showUsers(); $('#closeUserBtn').click(); } }, error: function() { error(); hideWait(); } }); </code></pre> <p>Logger writes that addresses is '[object Object]' but actually the valid array was sent to server</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload