Hello,
This is my entitymodel.xml file <entity entity-name="Employee" package-name="org.ofbiz.hello1" title="Hello Person Entity"> <field name="empId" type="id-ne" ></field> <field name="firstName" type="name"></field> <field name="lastName" type="name"></field> <field name="email" type="name"></field> <prim-key field="empId"/> </entity> This is part of EmployeeServices,java GenericValue employee = delegator.makeValue("Employee"); employee.put("empId",12); employee.put("firstName",firstName); employee.put("lastName", lastName); employee.put("email", email); when i am giving hard coded value for empId then its getting stored in DB. i want to autoassign that field so that i don't have to hard-code the value again and again ... Any help on this? Thanks in advance! |
Hi Prabhakar,
You should have service engine utility. In OFBiz for CRUD operation we use services. You can write service using entity-auto. Please refer example/services.xml for more reference. <service name="createExample" default-entity-name="Example" engine="entity-auto" invoke="create" auth="true"> Thanks & Regards -- Deepak Dixit HotWax Media Pvt. Ltd. www.hotwaxmedia.com Contact :- +91-98267-54548 Skype :- deepakdixit On Jul 13, 2012, at 10:47 AM, Prabhakar Pandey wrote: > Hello, > > This is my entitymodel.xml file > > <entity entity-name="Employee" package-name="org.ofbiz.hello1" title="Hello > Person Entity"> > > <field name="empId" type="id-ne" ></field> > <field name="firstName" type="name"></field> > <field name="lastName" type="name"></field> > <field name="email" type="name"></field> > <prim-key field="empId"/> > </entity> > > This is part of EmployeeServices,java > > GenericValue employee = delegator.makeValue("Employee"); > employee.put("empId",12); > employee.put("firstName",firstName); > employee.put("lastName", lastName); > employee.put("email", email); > > > when i am giving hard coded value for empId then its getting stored in DB. > i want to autoassign that field so that i don't have to hard-code the value > again and again ... Any help on this? > Thanks in advance! smime.p7s (6K) Download Attachment |
Also it would be great if any1 could tell me how can i retrieve values from
database using Java services and events only. On Fri, Jul 13, 2012 at 11:02 AM, Deepak Dixit <[hidden email] > wrote: > Hi Prabhakar, > > You should have service engine utility. > In OFBiz for CRUD operation we use services. You can write service using > entity-auto. > Please refer example/services.xml for more reference. > > <service name="createExample" default-entity-name="Example" > engine="entity-auto" invoke="create" auth="true"> > > > Thanks & Regards > -- > Deepak Dixit > HotWax Media Pvt. Ltd. > www.hotwaxmedia.com > Contact :- +91-98267-54548 > Skype :- deepakdixit > > On Jul 13, 2012, at 10:47 AM, Prabhakar Pandey wrote: > > > Hello, > > > > This is my entitymodel.xml file > > > > <entity entity-name="Employee" package-name="org.ofbiz.hello1" > title="Hello > > Person Entity"> > > > > <field name="empId" type="id-ne" ></field> > > <field name="firstName" type="name"></field> > > <field name="lastName" type="name"></field> > > <field name="email" type="name"></field> > > <prim-key field="empId"/> > > </entity> > > > > This is part of EmployeeServices,java > > > > GenericValue employee = delegator.makeValue("Employee"); > > employee.put("empId",12); > > employee.put("firstName",firstName); > > employee.put("lastName", lastName); > > employee.put("email", email); > > > > > > when i am giving hard coded value for empId then its getting stored in > DB. > > i want to autoassign that field so that i don't have to hard-code the > value > > again and again ... Any help on this? > > Thanks in advance! > > |
Prabhakar,
Use GenericDelegator class methods for doing so. Not sure if you go thru the practice application tutorial - https://cwiki.apache.org/OFBIZ/ofbiz-tutorial-a-beginners-development-guide.html -- Rishi Solanki On Fri, Jul 13, 2012 at 11:54 AM, Prabhakar Pandey <[hidden email]>wrote: > Also it would be great if any1 could tell me how can i retrieve values from > database using Java services and events only. > > > On Fri, Jul 13, 2012 at 11:02 AM, Deepak Dixit < > [hidden email] > > wrote: > > > Hi Prabhakar, > > > > You should have service engine utility. > > In OFBiz for CRUD operation we use services. You can write service using > > entity-auto. > > Please refer example/services.xml for more reference. > > > > <service name="createExample" default-entity-name="Example" > > engine="entity-auto" invoke="create" auth="true"> > > > > > > Thanks & Regards > > -- > > Deepak Dixit > > HotWax Media Pvt. Ltd. > > www.hotwaxmedia.com > > Contact :- +91-98267-54548 > > Skype :- deepakdixit > > > > On Jul 13, 2012, at 10:47 AM, Prabhakar Pandey wrote: > > > > > Hello, > > > > > > This is my entitymodel.xml file > > > > > > <entity entity-name="Employee" package-name="org.ofbiz.hello1" > > title="Hello > > > Person Entity"> > > > > > > <field name="empId" type="id-ne" ></field> > > > <field name="firstName" type="name"></field> > > > <field name="lastName" type="name"></field> > > > <field name="email" type="name"></field> > > > <prim-key field="empId"/> > > > </entity> > > > > > > This is part of EmployeeServices,java > > > > > > GenericValue employee = delegator.makeValue("Employee"); > > > employee.put("empId",12); > > > employee.put("firstName",firstName); > > > employee.put("lastName", lastName); > > > employee.put("email", email); > > > > > > > > > when i am giving hard coded value for empId then its getting stored in > > DB. > > > i want to autoassign that field so that i don't have to hard-code the > > value > > > again and again ... Any help on this? > > > Thanks in advance! > > > > > |
In reply to this post by Deepak Dixit-2
//you have to keep the input values in map like Map createPersonCtx = UtilMisc.toMap("empId",empId,"firstname", firstName, "lastname", lastName,"email",email); //then make the value GenericValue genEmp = delegator.makeValue("Employee"); //keep the value in the map genEmp.putAll(createPersonCtx); try { //save it in the database GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); delegator.createOrStore(employee); } catch (GenericEntityException e) { e.printStackTrace(); } NOTE: you have to import the following import java.util.Map; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.entity.GenericDelegator; import org.ofbiz.entity.GenericValue; import org.ofbiz.base.util.UtilMisc; |
Hello, What should i reply On Sat, Jan 24, 2015 at 2:28 PM, mateen.ahmed [via OFBiz] <[hidden email]> wrote:
|
Free forum by Nabble | Edit this page |