提交Set集合出错
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题主要出在这里:
Action下面没有brands,应该是Action下的productType.brands 但是不知道这样的话上面的配置应该怎么写?