Announcement Announcement Module
No announcement yet.
Data binding without using spring taglib Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Data binding without using spring taglib


    My html is built without using the spring taglib and now I'd like to bind the parameters of the form to a object in my controller.

    Currently my form looks like this

    <input type="text" name="frAccUserMgmt.userName"/>
    <input type="password" name="frAccUserMgmt.userPwd"/>
    The relevant part of my object is

    Class FrAccUserMgmt {
        private String userName;
        private Strint userPwd;
        // getter and setter
    My controller is

    Public ModelAndView doLogin(FrAccUserMgmt frAccUserMgmt) {
    Adding a BindingResult parameter to the controller doesn't help. It just simply says that there are no binding errors. Neither does adding a @ModelAttribute help.
    How do I go about binding it? I just get an empty object in my code.

  • #2
    Why not use the binding tags? Makes your life a lot easier but alas. Remove the frAccUserMgmt part of the name and make sure you have a get/setUserName etc. But beware it is oneway only! If there are errors you will not find your input fields pre-filled with the old values but get an empty form again...


    • #3
      Man you are awesome! I wouldn't have thought that spring would've been able to bind the parameters to the object without a reference to the name of the object like "frAccUserMgmt". This also means that I can't have two objects with the same field say addressLine1 as method parameters in the controller since spring won't be able tell which object to bind the addressLine1 field to, right? Or is there a way in which I can specify a form field to object field mapping?

      I'm not using the spring taglib since I'm not the one who's developing the front end. I suck at html. A professional HTML designer is making the front end who doesn't know Java. Plus he's using ExtJs which generates HTML markup using JavaScript.

      Thanks for the help!


      • #4
        You're welcome. If you aren't in control of the front-end you might want to take a look at Thymeleaf with that you simply reuse the HTML, add some additional parameters to the HTML tag and you get the best of both worlds.


        • #5
          Thanks for the suggestion. I'll look it up.

          Thanks again,