Announcement Announcement Module
No announcement yet.
Populate combo box data and carry over to DB Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Populate combo box data and carry over to DB

    I have a form

    User enters customer number and selects button

    Upon the click of the button, controller should fetch all states(Set of State pojos) that user lived in and should display on screen

    user selects one of the state(State pojo) as his favourite

    System should save his favourite state in DB.

    I have the code as described in the last thread of :

    I am noticing that setAsText is getting called before I send the request to DB for fetching the information
    regarding his favourite states. So obviously combobox on the screen is appearing as empty.

    1. I am seeing the following flow:

    button selection upon entering cust number: multiactioncontroller.getCustomerData(req,res, command)

    StateEditor.setAsText --> since this is the first time, obviously text is empty

    2. Also I noticed one thing. I have toString on State object. When I comment out toString(), I am receiving a numberformat exception why?

    3. Is there any way to populate combo boxes without using property editors?

  • #2
    I don't understand exactly what you are doing, but combos may be populated from standard java collections

    <form:select path="entityId">
    	<form:options items="${entityList}" itemValue="id" itemLabel="description" />				
    Just make a list with all your entities (entityList in the example), and put it in the model. Just put in itemLabel and itemValue, the names of the fields inside the entity that will be used as label and value in the combobox. itemValue shuld be a field that identifies the object in an univoque way (For example, the primary key in the database if you are using a Long number)

    Your form must have a field named entityId, where you will get the value (Just the value in the field determined by itemValue, not the whole object)