jpa - how to merge a shop entity to a client entity (many to one) in jsf -



jpa - how to merge a shop entity to a client entity (many to one) in jsf -

i'm trying merge existing shop new client in jsf isn't successful. programme consists off backing bean controller,an ejb , jsf page (register) have been able populate shoplist in combobox ui. here code.

register.xhtml:

clientcontroller.client.fname sfsb. property persisted trying merged. shop list (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>

backing bean class:

managedbean(name="clientcontroller") @requestscoped public class clientcontroller { @ejb clientejb clientejb; private client clt = new client(); private shop shp = new shop(); private string clientfname; //getters , setters public string register(shop shp){ this.shp = shp; clientejb.register(clt, shp); homecoming ""; }

ejb class:

@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); } }

adjust code follows:

xhtml:

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

managedbean

public string register(){ clientejb.register(clt, shp); homecoming ""; }

see also:

jsf 2 dropdown box example

jsf jpa ejb facelets

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -