Announcement Announcement Module
Collapse
No announcement yet.
Dropdownlist with selected value Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dropdownlist with selected value

    I have a form where I want to choose from users. Default, the user from the project is selected. The usersList is a list of User objects. The field must get a object input, so I wrote a initBinder to convert the users to ints. Now, I cannot get the author shown as the selected user. I must have something like <form:select path="user" selected="user.id"/>.

    When selecting a user from the dropdownlist, and submitting, it is saved correctly.

    How can I solve this?

    Thanks!

    To check the form and initBinder code, please refer to the attached txt file. I couldn't write it here (also with the code tags) because of the following error:
    You are only allowed to post URLs to other sites after you have made 5 posts or more.

  • #2
    What I did:

    Adding userId parameter in the Project class, and set it to the id of the user object when loading the form (in formBackingObject(...)). I also linked the dropdownlist with that userid.

    Comment


    • #3
      are you looking for a way to get the selected users userId?

      I'm sure your user is not an int. my approach is I will create a new command class with a int userId, and then

      Code:
      <form:select path="userId" items="${userList}" itemValue="user.id" itemLabel="user.name">
      </form:select>
      the above will help you if you want to get the userId as a parameter from the form and also in the same time to initially select any user you want from the formBackingObject method. when you initiate userId with a value the respected user will be automatically selected in your view

      so when the user submits the form you will have the selected users userId, so you will be able to retrieve the user details from database

      Comment


      • #4
        I already did what you said

        My english isn't that good.

        Thanks for your reply.

        Comment


        • #5
          you are welcome!

          Comment

          Working...
          X