Search code examples
javaspringjspspring-mvcspring-webflow

Display Set<State> using Spring MVC


I am getting PropertyNotFoundException while trying to populate select box in JSP using Spring MVC. I (think) I have all implementation correct. Can anyone point out if I missed anything.

Below is my code snippet:

Spring MVC in JSP

<form:select path="${field.fieldCode}">
    <form:options items="${states.code}" />
</form:select>

Country and State class

Class State {
  private Long id;
  private Country country;
  private String code;
  private String name;
}

Class Country {
  ....
  private Set<State> states;
}

Service Class

@Transactional(readOnly=true)
@Service("domainGeoService")
public class DomainGeoServiceImpl implements DomainGeoService {
  @Override
  public Set<State> getStates() {
    Country usa = (Country)sessionFactory.getCurrentSession().get(Country.class, 1L);
    return usa.getStates();
  }
}

Webflow config

<evaluate expression="domainGeoService.getStates()" result="viewScope.states"/>

**Exact exception I am getting **

Caused by: javax.el.PropertyNotFoundException: Property 'code' not found on type org.hibernate.collection.PersistentSet

Solution

  • Changing Spring MVC to following solved the issue.

    <form:select path="${field.fieldCode}" >
        <form:option value="" label="** Select State **"></form:option>
        <form:options items="${states}" itemValue="code" itemLabel="code"></form:options>
    </form:select>