我有以下JSF片段:
<h:form>
<h:selectOneMenu value="#{customerBean.customer.country.id}" >
<f:selectItem itemLabel="-SELECT ONE-"/>
<f:selectItems value="#{customerBean.countries}" var="country" itemLabel="#{country.name}" itemValue="#{country.id}" />
</h:selectOneMenu>
<a4j:commandButton value="Update" action="#{customerBean.update}" execute="@form" />
</h:form>
豆子:
@ManagedBean
@ViewScoped
public class CustomerBean implements Serializable
{
private Customer customer;
private List<Country> countries;
public String update()
{
//These fields are not available for the user to edit.
customer.setStatus("M");
customer.setUpdateUser("ADMIN");
customer.setUpdateDate(new Date(Calendar.getInstance().getTimeInMillis()));
customerDAO.update(customer);
return null;
}
}
每当我为给定客户选择不同的国家并尝试保存时,我就会收到上述错误,就好像我正在尝试更改国家/地区的ID,而不是仅仅将国家/地区实例与客户相关联。
我正在使用Richfaces 4 / Tomcat 7 / Hibernate 3.6
关于我做错什么的任何想法?