Search code examples
springjspspring-mvcspring-form

Spring form select not displaying the value as the selected value


I am using a form select , however the value for the drop down is not showing up as selected.I have the following Model

 public class Customer{
 public ConditionalBean conditional
}

The ConditionalBean is as follows:

public class ConditionalBean {
 private String conditionalName;
 private String conditionalType;
}

In the jsp I have the following

<form:select path=customer.conditional.conditionalName>
  <form:options items="${optionsMap}"/>
 </form:select>

When I display the conditional name

   <td>${customer.conditional.conditionalName}</td>

it is correctly showing up

However on the drop down the value of the select is not being shown as selected. I have been able to successfully do it for other dropdowns ,where the path references a regular String. Here, it is the ConditionalBean object's conditonalName.

Any idea how to fix this? I looked into using using a PropertyEditorSupport but not sure how to use it.

The options for the select were created as follows:

   Map<String,String>optionsMap = new HashMap<String,String>
   optionsMap.put(conditionalName,conditionalName);

Solution

  • Thanks kuldeep S Chauhan for the tip. I checked the values in the Map that was populating the options and identified that the key had a trailing space. After trimming the space, it is correctly being displayed. Thanks!