如何将商店实体合并到客户实体(多对一)jsf
问题描述:
我试图将现有商店合并到jsf中的新客户端,但它不成功。该程序基本上包括一个支持bean控制器,一个ejb和jsf页面(注册),我已经能够在combobox UI中填充shoplist。这里是代码。如何将商店实体合并到客户实体(多对一)jsf
register.xhtml:
clientcontroller.client.fname
是一个SFSB。 Property
已经存在,但试图合并。
从列表中店(shopcontroller.shopList
)
<h:form>
<h:panelGrid columns="3" >
<h:outputText value="Select From.
Available Shops :" />
<h:selectOneMenu value="#.
{shopController.shop}" >
<f:selectItems var="s" value="#.
{shopController.shopList}" />
</h:selectOneMenu>
<h:commandButton value="register".
action="#{clientcontroller.Register(s)}" />
</h:panelGrid>
</h:form>
支撑类:
ManagedBean(name="clientcontroller")
@RequestScoped
public class clientController {
@EJB ClientEJB clientEJB;
private Client clt = new Client();
private Shop shp = new Shop();
private String clientfname;
//getters and setters
public String Register(Shop shp){
this.shp = shp;
clientEJB.register(clt, shp);
return "";
}
EJB类:
@Stateful
@LocalBean
public class ClientEJB {
@PersistenceContext
EntityManager em;
public void addClient(Client clt){
em.persist(clt);
}
public void register(Client c ,Shop s){
c.getShopList().add(s);
s.setAvailability("false");
s.setClientid(c);
em.merge(s);
em.merge(c);
}
}
答
调整你的代码如下:
XHTML:
<h:commandButton value="register" action="#{clientcontroller.Register}" />
ManagedBean
public String Register(){
clientEJB.register(clt, shp);
return "";
}
另请参见:
那么究竟是什么问题?你在期待什么,你会得到什么? – kostja 2013-02-13 09:02:18