java - 使用 Spring MVC 显示 Set<State>

标签 java spring jsp spring-mvc spring-webflow

我在尝试使用 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 更改为以下解决了该问题。

<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>

关于java - 使用 Spring MVC 显示 Set<State>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28836740/

相关文章:

java - KeyEvent.KEYCODE_ENTER如何引发

spring - 保持 Spring Security session 超时的区域设置

java - Spring 响应中 JSON 中位置 0 处出现意外标记 S

java - java中的椭圆曲线密码学

java - 如何在 Tomcat 中找到 Apache HTTP Server

java - 函数退出后,函数内部打开的文件/文件指针(缓冲读取器)会发生什么?

java - 数据库中的数据与java字符串中的数据不同

java - RabbitMQ 不等价参数 'x-max-length-bytes' 异常

javascript - 删除版 block 后如何刷新

spring - 如何使用外部目录资源