我在尝试使用Spring MVC填充JSP中的选择框时遇到PropertyNotFoundException。我(认为)我的所有实现都是正确的。谁能指出我是否错过了什么。
以下是我的代码段:
JSP中的Spring MVC
<form:select path="${field.fieldCode}">
<form:options items="${states.code}" />
</form:select>
国家和州级
Class State {
private Long id;
private Country country;
private String code;
private String name;
}
Class Country {
....
private Set<State> states;
}
服务等级
@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配置
<evaluate expression="domainGeoService.getStates()" result="viewScope.states"/>
**我得到的确切异常**
Caused by: javax.el.PropertyNotFoundException: Property 'code' not found on type org.hibernate.collection.PersistentSet
最佳答案
将Spring MVC更改为following可解决此问题。
<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>