提交Set集合出错? 400 报错
package oshop.entity;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
/**
* 产品品牌
*
* @author sky
*
*/
@Entity
@org.hibernate.annotations.Entity(dynamicUpdate = true)
@Table(name = "brand")
public class Brand extends BaseEntity {
/**
*
*/
private static final long serialVersionUID = -982632398252926845L;
/**
* 产品类型
*/
private Set<ProductType> productTypes;
private String name;
private String siteUrl;
@Column(unique = true, nullable = false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSiteUrl() {
return siteUrl;
}
public void setSiteUrl(String siteUrl) {
this.siteUrl = siteUrl;
}
@ManyToMany(fetch = FetchType.LAZY)
public Set<ProductType> getProductTypes() {
return productTypes;
}
public void setProductTypes(Set<ProductType> productTypes) {
this.productTypes = productTypes;
}
}
package oshop.entity;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
/**
* 产品类型
*
* @author sky
*
*/
@Entity
@Table(name = "product_type")
public class ProductType extends BaseEntity {
private static final long serialVersionUID = 4500336342773347538L;
private ProductCategory parentCategory; // 商品分类
private String name;// 商品类型名称
private Set<ProductTypeAttribute> productTypeAttributes; // 商品属性
private Set<Brand> brands;// 商品类型可选的品牌
private String priceRange;// 价格区间
@ManyToOne(optional = false, fetch = FetchType.LAZY)
public ProductCategory getParentCategory() {
return parentCategory;
}
public void setParentCategory(ProductCategory parentCategory) {
this.parentCategory = parentCategory;
}
@Column(nullable = false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY, mappedBy = "productType")
public Set<ProductTypeAttribute> getProductTypeAttributes() {
return productTypeAttributes;
}
public void setProductTypeAttributes(
Set<ProductTypeAttribute> productTypeAttributes) {
this.productTypeAttributes = productTypeAttributes;
}
public String getPriceRange() {
return priceRange;
}
public void setPriceRange(String priceRange) {
this.priceRange = priceRange;
}
@ManyToMany(fetch = FetchType.LAZY)
public Set<Brand> getBrands() {
return brands;
}
public void setBrands(Set<Brand> brands) {
this.brands = brands;
}
}
<tr> <th class="label">可选品牌:</th> <td><#if (brandList?size > 0)> <#list brandList as brand> <ul class="checkboxList"> <li>
<input id="brand_${brand.id}" type="checkbox" name="productType.brands.makeNew[${brand_index}].id" value="${brand.id}" /> <label for="brand_${brand.id}" title="${(brand.siteUrl)!}"> ${brand.name} </label> </li> </ul> </#list> </#if> <div class="cb"></div> </td> </tr>
properites:
KeyProperty_brands=id Element_brands=oshop.entity.Brand CreateIfNull_brands=true
提交表单报错是:
2011-3-11 10:37:58 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: Error setting expression 'productType.brands.makeNew[0].id' with value '[Ljava.lang.String;@472ebf9a'
ognl.OgnlException: Error getting property descriptor: null
at com.opensymphony.xwork2.ognl.accessor.XWorkCollectionPropertyAccessor.getProperty(XWorkCollectionPropertyAccessor.java:126)
at com.opensymphony.xwork2.ognl.accessor.XWorkListPropertyAccessor.getProperty(XWorkListPropertyAccessor.java:80)
找了一上午了,网上说要写properties文件和makeNew也写了。就是提交不上去。Set new 过了也是这个错误。Brand里面有getId,setId
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
问题主要出在这里:
Action下面没有brands,应该是Action下的productType.brands 但是不知道这样的话上面的配置应该怎么写?