Announcement Announcement Module
Collapse
No announcement yet.
binding to an object rather than a String or primitive Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • binding to an object rather than a String or primitive

    Hello,

    I have a question that's pretty simlar to this unanswered question:
    forum.springsource.org/showthread.php?t=65563&highlight=bind+list

    let's say I have the following:

    class User{
    Breakfast todaysBreakfast
    }

    If I want to have a selectbox of possible breakfasts, can I easily set things up so that, after a form submission, I'll have a User command object with the appropritae Breakfast object? The examples I'm seeing (chapter 13 of the docs) all seem to follow this model:

    class User{
    String todaysBreakfast
    }

    Where Spring just literally interprets the value of the form and populates a bean with a primitive type, rather than intelligently selecting from a list of objects.

    I hope this makes sense. Thanks for the help.

  • #2
    Good question, I'd like to know the answer too!

    Comment


    • #3
      I've cross-posted a possibly better explanation of my question on StackOverflow: http://stackoverflow.com/questions/5...g-or-primitive

      Comment


      • #4
        I suggest chapter 5 of the reference guide that explains all about validation and data binding.

        1) Create a PropertyEditor which converts strings into BreakFast objects
        2) Register it with the DataBinder
        3) Add all possible Breakfasts to the reference data not the command (as you do in your blog)
        4) Deploy and test

        The sample application does show this as the fact that it is explained in the reference guide chapter 5.

        Comment


        • #5
          Originally posted by Marten Deinum View Post
          I suggest chapter 5 of the reference guide that explains all about validation and data binding.

          1) Create a PropertyEditor which converts strings into BreakFast objects
          2) Register it with the DataBinder
          3) Add all possible Breakfasts to the reference data not the command (as you do in your blog)
          4) Deploy and test

          The sample application does show this as the fact that it is explained in the reference guide chapter 5.
          Thanks Martin,
          It seems that PropertyEditors create transform single String objects in to brand new objects and sets properties using those new objects. Using a PropertyEditor, can I actually set todaysBreakfast to a Breakfast object from my reference data, or do I have to create a brand new Breakfast?

          Comment


          • #6
            Your reference data isn't there anymore so that isn't going to be useable. So you either have to create a new one or retrieve one from the database (if it is an id or something like that).

            Comment


            • #7
              riiiiight. That's been my whole conceptual block with this, the request/response cycle and the stateless nature of the web. Sometimes I forget. I'm a tiny bit less stupid now than I was at the beginning of the day. Thanks!

              Comment

              Working...
              X