can not set an entity property through selectOneMenu
surajmundada Sep 21, 2012 1:36 PMHi,
I am using Seam 2.2.0 GA with Jboss AS 4.2.
I am trying to display a list and set the selected value from list in an entity and persist it. Following are code snippets:
<s:decorate id="productCategoryField" template="layout/edit.xhtml">
<ui:define name="label">Product Category</ui:define>
<h:selectOneMenu id="menuProductCategory" value="#{retaileraccount.productCategory}">
<s:selectItems value="#{regsiterRetailer.listProductCategory}" var="pCategory" label="#{pCategory.productCategoryName}" noSelectionLabel="Please Select"/>
</h:selectOneMenu>
</s:decorate>
Entities are as follow:
@Entity
@Name("retaileraccount")
@Scope(ScopeType.SESSION)
@Table(name="retailer_Account")
public class RetailerAccount implements Serializable
{
@Id @GeneratedValue
private int retailerId;
@ManyToOne()
private ProductCategory productCategory;
@Entity
@Name("productcategory")
@Scope(ScopeType.SESSION)
@Table(name="product_category")
public class ProductCategory implements Serializable {
@Id @GeneratedValue
private Long productCategoryId;
private String productCategoryName;
private String productCategoryDetails;
Action
@Stateless
@Name("regsiterRetailer")
public class RegsiterRetailerActionBean implements RegsiterRetailerAction {
@Logger private Log log;
@In StatusMessages statusMessages;
@In("retaileraccount")
RetailerAccount retailerAccount;
@PersistenceContext
private EntityManager em;
public RetailerAccount getRetailerAccount() {
return retailerAccount;
}
public void setRetailerAccount(RetailerAccount retailerAccount) {
this.retailerAccount = retailerAccount;
}
public String regsiter() {
// implement your business logic here
log.info("regsiterRetailerAction.regsiterRetailerAction() action called");
List existingList = em.createQuery("select establishmentName from RetailerAccount " +
"where establishmentName = #{retailerAccount.establishmentName}").getResultList();
if(existingList.size() != 0) {
FacesMessages.instance().add("Shop #{retailerAccount.establishmentName} already exists");
return null;
}
em.persist(retailerAccount);
log.info("Registered new establishment #{retailerAccount.establishmentName}");
return null;
}
public List getListProductCategory() {
List listProductCategory = em.createQuery("select productCategory from ProductCategory productCategory").getResultList();
System.out.println("here in getListProductCategory");
return listProductCategory;
}
}
SQL schema:
CREATE TABLE `product_category` (
`product_category_id` int(11) NOT NULL auto_increment,
`product_category_name` varchar(250) NOT NULL default '',
`product_category_details` varchar(250) default NULL,
PRIMARY KEY (`product_category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `retailer_account` (
`retailer_id` int(11) NOT NULL auto_increment,
`product_category` int(11) NOT NULL default '0',
PRIMARY KEY (`retailer_id`),
KEY `product_category` (`product_category`),
CONSTRAINT `retailer_account_ibfk_1` FOREIGN KEY (`product_category`) REFERENCES `product_category` (`product_category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
When I run this, I get error as
Property 'productcategory' not found on type com.shoppingthreads.retailer.entity.RetailerAccount
I cross checked with sample examples and seems everything is correct.
Can somebody help with identifying the problem and solution?
Thanks.
Suraj