我正在尝试将现有商店合并到jsf中的新客户端,但这并不成功。该程序基本上由一个支持bean控制器,一个ejb和jsf页面(寄存器)组成,我已经能够在一个comboBox UI中填充shoplist。这是代码。
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>
支持bean类:
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);
}
}
答案 0 :(得分:0)
按如下方式调整代码:
XHTML:
<h:commandButton value="register" action="#{clientcontroller.Register}" />
ManagedBean
public String Register(){
clientEJB.register(clt, shp);
return "";
}
另见: