0

我正在尝试将现有商店合并到 jsf 中的新客户,但没有成功。该程序基本上由一个支持 bean 控制器、一个 ejb 和 jsf 页面(注册)组成,我已经能够在组合框 UI 中填充购物清单。这是代码。

注册.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);
  }
}
4

1 回答 1

0

调整您的代码如下:

XHTML:

  <h:commandButton value="register" action="#{clientcontroller.Register}" />

托管豆

  public String Register(){
      clientEJB.register(clt, shp);
      return ""; 
  }

也可以看看:

于 2013-02-13T09:44:06.003 回答