In this EJB-JPA Tutorial, we will persist one side of the Many to One Join. Means, we will show a form so that user can create a new employee and map to existing Job. The JSP file loads Job to show in the combo field (HTML Select and Option).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%--Sample 8.12: Page Include Directive --%> <%@ page import='javax.naming.InitialContext'%> <%@ page import='java.util.List' %> <%@ page import='tube.codingexamples.ejb.statelessbean.EmpJobBeanRemote'%> <%@ page import='javax.naming.NamingException'%> <%@ page import='tube.coding.examples.jpa.entity.Job' %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <!-- Sample 8.13: Form to Create Employee --> <form action="CreateEmployeeSlet" method="post"> First Name: <input name="fname" type="text" size="25" value=""><br> Mid Name: <input name="mname" type="text" size="10" value=""><br> Last Name: <input name="lname" type="text" size="25" value=""><br> Job Level: <input name="level" type="text" size="3" value="100"><br> <strong>Job Level should be between 10 to 250</strong> Pick a Job: <br> <Select name="Job" onchange="form."> <% //Sample 8.14: Populate the Select Options List<Job> jobs = null; InitialContext ctx = new InitialContext(); EmpJobBeanRemote ejbEmpJob = (EmpJobBeanRemote) ctx.lookup( "java:global/EJBEar/EJBBean/EmpJobBean!tube.codingexamples.ejb.statelessbean.EmpJobBeanRemote"); jobs = ejbEmpJob.queryJobs(); Job job = null; for (int index=0; index < jobs.size(); index++ ) { job = jobs.get(index); %> <option value="<%=job.getJobId() %>"> <%=job.getJobDesc() %> Exp Demand:[<%= job.getMinExp() %> - <%= job.getMaxExp() %>] </option> <% } %> </Select><br/> <input type="submit" name="submit" value="submit"> </form> </body> </html> |
Categories: JavaEE-EJB-Tube