Enhanced JSF support
diff --git a/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/CreateEmployee.java b/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/CreateEmployee.java
index 59fc476..93aa1c3 100644
--- a/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/CreateEmployee.java
+++ b/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/CreateEmployee.java
@@ -12,8 +12,6 @@
******************************************************************************/
package eclipselink.example.jpa.employee.web;
-import java.util.List;
-
import javax.faces.bean.ManagedBean;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
@@ -30,16 +28,16 @@
*/
@ManagedBean
public class CreateEmployee {
-
+
private String firstName;
-
+
private String lastName;
-
+
private String gender;
-
+
private EntityManagerFactory emf;
- protected static final String PAGE = "employee-create";
+ protected static final String PAGE = "employee/create?faces-redirect=true";
public String getFirstName() {
return firstName;
@@ -69,7 +67,7 @@
return emf;
}
- @PersistenceUnit(unitName="employee")
+ @PersistenceUnit(unitName = "employee")
public void setEmf(EntityManagerFactory emf) {
this.emf = emf;
}
@@ -79,18 +77,20 @@
emp.setFirstName(getFirstName());
emp.setLastName(getLastName());
emp.setGender(Gender.valueOf(getGender()));
-
+
EntityManager em = getEmf().createEntityManager();
try {
- em.getTransaction().begin();
- em.persist(emp);
- em.getTransaction().commit();
+ em.getTransaction().begin();
+ em.persist(emp);
+ em.getTransaction().commit();
} finally {
em.close();
}
-
-
- System.out.println("CERATE: " + emp);
+
+ return EmployeeList.PAGE;
+ }
+
+ public String cancel() {
return EmployeeList.PAGE;
}
}
diff --git a/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/CreateEmployee b/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/EditEmployee.java
similarity index 68%
rename from employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/CreateEmployee
rename to employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/EditEmployee.java
index 4736466..1921dbf 100644
--- a/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/CreateEmployee
+++ b/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/EditEmployee.java
@@ -12,10 +12,7 @@
******************************************************************************/
package eclipselink.example.jpa.employee.web;
-import java.util.List;
-
import javax.faces.bean.ManagedBean;
-import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
@@ -28,27 +25,42 @@
* @since EclipseLink 2.3.0
*/
@ManagedBean
-public class EmployeeList {
-
+public class EditEmployee {
+
+ private Employee employee;
+
private EntityManagerFactory emf;
- protected static final String PAGE = "index";
+ protected static final String PAGE = "employee/edit?faces-redirect=true";
+
+ public Employee getEmployee() {
+ return employee;
+ }
+
+ public void setEmployee(Employee employee) {
+ this.employee = employee;
+ }
public EntityManagerFactory getEmf() {
return emf;
}
- @PersistenceUnit(unitName="employee")
+ @PersistenceUnit(unitName = "employee")
public void setEmf(EntityManagerFactory emf) {
this.emf = emf;
}
- public List<Employee> getEmployees() {
- EntityManager em = getEmf().createEntityManager();
- try {
- return em.createQuery("SELECT e FROM Employee e ORDER BY e.id", Employee.class).getResultList();
- } finally {
- em.close();
- }
+ public String edit() {
+ this.employee = new Employee();
+
+ return PAGE;
+ }
+
+ public String save() {
+ return EmployeeList.PAGE;
+ }
+
+ public String cancel() {
+ return PAGE;
}
}
diff --git a/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/EmployeeList.java b/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/EmployeeList.java
index 4736466..974e9b3 100644
--- a/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/EmployeeList.java
+++ b/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/EmployeeList.java
@@ -32,7 +32,7 @@
private EntityManagerFactory emf;
- protected static final String PAGE = "index";
+ protected static final String PAGE = "employee/search-results?faces-redirect=true";
public EntityManagerFactory getEmf() {
return emf;
@@ -51,4 +51,8 @@
em.close();
}
}
+
+ public String create() {
+ return CreateEmployee.PAGE;
+ }
}
diff --git a/employee/employee.web/src/main/webapp/WEB-INF/template.xhtml b/employee/employee.web/src/main/webapp/WEB-INF/template.xhtml
new file mode 100644
index 0000000..90f7237
--- /dev/null
+++ b/employee/employee.web/src/main/webapp/WEB-INF/template.xhtml
@@ -0,0 +1,58 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:fmt="http://java.sun.com/jstl/fmt">
+<head>
+<title><ui:insert name="title" /></title>
+<link rel="stylesheet" type="text/css" href="/default.css" />
+</head>
+<body>
+ <f:view>
+ <h:form>
+ <table width="100%">
+ <tr>
+ <td width="100%">
+ <table width="100%">
+ <tr>
+ <td width="25%" height="100" valign="middle">
+ <h:graphicImage name="images/eclipselink-logo.png" alt="EclipseLink" height="80"/>
+ </td>
+ <td width="50%" align="center" valign="middle">
+ <h1 class="sansserif">Employee Example</h1>
+ </td>
+ <td width="25%" valign="middle"><div align="center">
+ <h:commandButton action="/index" value="Home" />
+ </div></td>
+ </tr>
+ <tr>
+ <td colspan="3" bgcolor="#0033CC" height="40">
+ <h2 class="sansserif">
+ <font color="white" face="verdana"><ui:insert
+ name="subtitle" /></font>
+ </h2>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="3"><h:messages /></td>
+ </tr>
+ </table>
+
+ </h:form>
+ <p />
+ <ui:insert name="body" />
+ <p />
+ <table width="100%" class="accent">
+ <tr>
+ <td height="20" bgcolor="#0033CC"></td>
+ </tr>
+ </table>
+ </f:view>
+</body>
+</html>
diff --git a/employee/employee.web/src/main/webapp/admin/index.xhtml b/employee/employee.web/src/main/webapp/admin/index.xhtml
new file mode 100644
index 0000000..71774b8
--- /dev/null
+++ b/employee/employee.web/src/main/webapp/admin/index.xhtml
@@ -0,0 +1,22 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core">
+
+
+<ui:composition template="/WEB-INF/template.xhtml">
+ <ui:define name="title">EclipseLink Employee Example</ui:define>
+ <ui:define name="subtitle">Administration</ui:define>
+ <ui:define name="body">
+ <h:form>
+ <div align="center">
+ <h:panelGrid width="400" columns="1" border="1">
+ </h:panelGrid>
+ </div>
+ </h:form>
+ </ui:define>
+</ui:composition>
+</html>
diff --git a/employee/employee.web/src/main/webapp/default.css b/employee/employee.web/src/main/webapp/default.css
new file mode 100644
index 0000000..bf83d77
--- /dev/null
+++ b/employee/employee.web/src/main/webapp/default.css
@@ -0,0 +1,206 @@
+#blockBuster {
+ position:relative;
+ z-index:5;
+ background:transparent url('/home/images/blockBuster.png') no-repeat;
+ height:194px;
+}
+
+#bbContent {
+ width:630px;
+ height:194px;
+ float:left;
+}
+
+#bbContent ul {
+ clear:both;
+ margin-left:5px;
+ padding-top:110px;
+}
+
+#bbContent ul li {
+ float:left;
+ text-align:center;
+ width:120px;
+ padding:0 0.5% 0 0;
+ height:65px;
+ margin:0px;
+}
+
+#bbContent ul li a {
+ color:#000;
+ font-size:11px;
+ font-weight:normal;
+}
+
+#bbNav {
+ float:left;
+ height:194px;
+ width:347px;
+}
+
+#bbNav ul {
+ margin:10px 0 0 15px;
+ width:350px;
+ text-align:left;
+ float:left;
+}
+
+#bbNav ul li {
+ float:left;
+ margin-right:10px;
+ padding:5px 1px;
+ width:142px;
+ height:20%;
+ border-top:1px white dotted;
+}
+
+#bbNav ul li.bottom {
+ border-bottom:1px white dotted;
+}
+
+#bbNav ul li a {
+ font-size:15px;
+ color:#000;
+}
+
+#bbNav ul li a img {
+ padding-right:5px;
+}
+
+
+#bbNav ul li.downloads a {
+ font-size:22px;
+}
+
+#bbNav ul li.downloads a img {
+ position:relative;
+ top:-10px;
+
+}
+
+#bbNav #buttonHolder {
+ margin:30px 0 -30px 15px;
+ padding-left:15px;
+ text-align:center;
+}
+
+#bbNav #downloadButton {
+ width:295px;
+ height:60px;
+ display:block;
+}
+
+.clearer {
+ clear:both;
+}
+
+.posted {
+ color:#888;
+ font-size:8px;
+}
+
+
+#promos {
+ text-align:center;
+ padding:20px;
+}
+.epicLegend
+{
+ float: left;
+ font-size: 10px;
+}
+.epicLegend img
+{
+ position: relative;
+ top: 4px;
+}
+
+#sitesHolder.visible {
+ display:block;
+}
+
+#sitesHolder.invisible {
+ display:none;
+}
+
+.rss {
+ float:right;
+}
+
+.none {
+ background:transparent !important;
+ border:0px !important;
+}
+
+.new {
+ list-style: outside url('/home/images/new.png') !important;
+ margin-left:20px !important;
+}
+
+.updated {
+ list-style: outside url('/home/images/update.png') !important;
+ margin-left:20px !important;
+}
+
+.new * , .updated *{
+ position:relative;
+ top:-4px;
+}
+
+.epicFeed a{
+ color:#4B4D47;
+}
+
+.epicFeed li {
+ padding:0px !important;
+}
+
+.liveFeed li {
+ padding:0px !important;
+}
+
+.liveFeed a {
+ color:#4B4D47;
+}
+
+.feedMore {
+ border:0px !important;
+ text-align:right;
+}
+
+.newcomer {
+ position:absolute;
+ top:35px;
+ right:359px;
+ text-align:center;
+}
+.newcomer a {
+ color:#000;
+ font-size:11px;
+ font-weight:bold;
+}
+
+.labsActive {
+ font-size:10px;
+ font-weight:normal;
+}
+#working_groups{
+ text-align: center;
+
+}
+#working_groups img{
+ padding:8px 45px;
+}
+div.feedMore{
+
+ border-top: 1px dotted #E9E9EE !important;
+ margin-bottom: 10px;
+padding: 5px 0 0 0;
+ margin:0 14px;
+}
+div.feedMore a{
+ padding: 0px 5px 25px 0;;
+ display: block;
+ text-align:right;
+ clear:both;
+}
\ No newline at end of file
diff --git a/employee/employee.web/src/main/webapp/employee-create.xhtml b/employee/employee.web/src/main/webapp/employee/create.xhtml
similarity index 83%
rename from employee/employee.web/src/main/webapp/employee-create.xhtml
rename to employee/employee.web/src/main/webapp/employee/create.xhtml
index b821db1..d1dcb82 100644
--- a/employee/employee.web/src/main/webapp/employee-create.xhtml
+++ b/employee/employee.web/src/main/webapp/employee/create.xhtml
@@ -7,12 +7,12 @@
xmlns:f="http://java.sun.com/jsf/core">
-<ui:composition template="template.jsf">
- <ui:define name="title">Create Employee</ui:define>
+<ui:composition template="/WEB-INF/template.xhtml">
+ <ui:define name="title">Employee Example</ui:define>
+ <ui:define name="subtitle">Create Employee</ui:define>
<ui:define name="body">
<h:form>
<div align="center">
- <h2>Create New Employee</h2>
<h:panelGrid width="400" columns="2" border="1" styleClass="pretty">
<h:outputLabel value="First Name:" />
<h:inputText value="#{createEmployee.firstName}" />
@@ -26,7 +26,7 @@
<f:facet name="footer">
<div align="center">
<h:commandButton value="Create" action="#{createEmployee.create}" />
- <h:commandButton value="Cancel" action="#{createDivision.cancel}" />
+ <h:commandButton value="Cancel" action="#{createEmployee.cancel}" />
</div>
</f:facet>
</h:panelGrid>
diff --git a/employee/employee.web/src/main/webapp/employee-create.xhtml b/employee/employee.web/src/main/webapp/employee/edit.xhtml
similarity index 63%
copy from employee/employee.web/src/main/webapp/employee-create.xhtml
copy to employee/employee.web/src/main/webapp/employee/edit.xhtml
index b821db1..167ade9 100644
--- a/employee/employee.web/src/main/webapp/employee-create.xhtml
+++ b/employee/employee.web/src/main/webapp/employee/edit.xhtml
@@ -7,26 +7,26 @@
xmlns:f="http://java.sun.com/jsf/core">
-<ui:composition template="template.jsf">
- <ui:define name="title">Create Employee</ui:define>
+<ui:composition template="/WEB-INF/template.xhtml">
+ <ui:define name="title">EclipseLink Employee Example</ui:define>
+ <ui:define name="subtitle">Edit Employee</ui:define>
<ui:define name="body">
<h:form>
<div align="center">
- <h2>Create New Employee</h2>
<h:panelGrid width="400" columns="2" border="1" styleClass="pretty">
<h:outputLabel value="First Name:" />
- <h:inputText value="#{createEmployee.firstName}" />
+ <h:inputText value="#{editEmployee.employee.firstName}" />
<h:outputLabel value="Last Name:" />
- <h:inputText value="#{createEmployee.lastName}" />
+ <h:inputText value="#{editEmployee.employee.lastName}" />
<h:outputLabel value="Gender:" />
- <h:selectOneMenu value="#{createEmployee.gender}">
+ <h:selectOneMenu value="#{editEmployee.employee.gender}">
<f:selectItem id="male" itemLabel="Male" itemValue="Male" />
<f:selectItem id="female" itemLabel="Female" itemValue="Female" />
</h:selectOneMenu>
<f:facet name="footer">
<div align="center">
- <h:commandButton value="Create" action="#{createEmployee.create}" />
- <h:commandButton value="Cancel" action="#{createDivision.cancel}" />
+ <h:commandButton value="Save" action="#{editEmployee.save}" />
+ <h:commandButton value="Cancel" action="#{editEmployee.cancel}" />
</div>
</f:facet>
</h:panelGrid>
diff --git a/employee/employee.web/src/main/webapp/employee-edit.xhtml b/employee/employee.web/src/main/webapp/employee/search-results.xhtml
similarity index 69%
rename from employee/employee.web/src/main/webapp/employee-edit.xhtml
rename to employee/employee.web/src/main/webapp/employee/search-results.xhtml
index 4d34d3d..d2188b9 100644
--- a/employee/employee.web/src/main/webapp/employee-edit.xhtml
+++ b/employee/employee.web/src/main/webapp/employee/search-results.xhtml
@@ -7,10 +7,10 @@
xmlns:f="http://java.sun.com/jsf/core">
-<ui:composition template="template.jsf">
+<ui:composition template="/WEB-INF/template.xhtml">
<ui:define name="title">EclipseLink Employee Example</ui:define>
+ <ui:define name="subtitle">Employee Search</ui:define>
<ui:define name="body">
- <h2>Employees</h2>
<h:form>
<div align="center">
<h:dataTable var="emp" value="#{employeeList.employees}" border="1"
@@ -28,6 +28,16 @@
<f:facet name="header">First Name</f:facet>
<h:outputText value="#{emp.firstName}" />
</h:column>
+ <h:column>
+ <h:commandLink action="#{editEmployee.edit}" value="Edit">
+ <f:param name="id" value="#{emp.id}"/>
+ </h:commandLink>
+ </h:column>
+ <h:column>
+ <h:commandLink action="#{deleteEmployee.confirm}" value="Delete">
+ <f:param name="id" value="#{emp.id}"/>
+ </h:commandLink>
+ </h:column>
</h:dataTable>
</div>
diff --git a/employee/employee.web/src/main/webapp/employees.xhtml b/employee/employee.web/src/main/webapp/employees.xhtml
deleted file mode 100644
index 4d34d3d..0000000
--- a/employee/employee.web/src/main/webapp/employees.xhtml
+++ /dev/null
@@ -1,38 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-<html xmlns="http://www.w3.org/1999/xhtml"
- xmlns:ui="http://java.sun.com/jsf/facelets"
- xmlns:h="http://java.sun.com/jsf/html"
- xmlns:f="http://java.sun.com/jsf/core">
-
-
-<ui:composition template="template.jsf">
- <ui:define name="title">EclipseLink Employee Example</ui:define>
- <ui:define name="body">
- <h2>Employees</h2>
- <h:form>
- <div align="center">
- <h:dataTable var="emp" value="#{employeeList.employees}" border="1"
- styleClass="pretty" width="500">
- <f:facet name="header">Employees</f:facet>
- <h:column>
- <f:facet name="header">ID</f:facet>
- <h:outputText value="#{emp.id}" />
- </h:column>
- <h:column>
- <f:facet name="header">Last Name</f:facet>
- <h:outputText value="#{emp.lastName}" />
- </h:column>
- <h:column>
- <f:facet name="header">First Name</f:facet>
- <h:outputText value="#{emp.firstName}" />
- </h:column>
- </h:dataTable>
-
- </div>
- <p> </p>
- </h:form>
- </ui:define>
-</ui:composition>
-</html>
diff --git a/employee/employee.web/src/main/webapp/index.xhtml b/employee/employee.web/src/main/webapp/index.xhtml
index 6e8d808..5ffd6d4 100644
--- a/employee/employee.web/src/main/webapp/index.xhtml
+++ b/employee/employee.web/src/main/webapp/index.xhtml
@@ -7,34 +7,14 @@
xmlns:f="http://java.sun.com/jsf/core">
-<ui:composition template="template.jsf">
- <ui:define name="title">EclipseLink Employee Example</ui:define>
+<ui:composition template="/WEB-INF/template.xhtml">
+ <ui:define name="title">Employee Example</ui:define>
+ <ui:define name="subtitle">Home</ui:define>
<ui:define name="body">
<h:form>
- <div align="center">
- <h:dataTable var="emp" value="#{employeeList.employees}" border="1"
- styleClass="pretty" width="500">
- <f:facet name="header">All Employees</f:facet>
- <h:column>
- <f:facet name="header">ID</f:facet>
- <h:outputText value="#{emp.id}" />
- </h:column>
- <h:column>
- <f:facet name="header">Last Name</f:facet>
- <h:outputText value="#{emp.lastName}" />
- </h:column>
- <h:column>
- <f:facet name="header">First Name</f:facet>
- <h:outputText value="#{emp.firstName}" />
- </h:column>
- <h:column>
- <f:facet name="header">Gender</f:facet>
- <h:outputText value="#{emp.gender}" />
- </h:column>
- </h:dataTable>
-
- </div>
- <p> </p>
+ <h:commandLink action="#{employeeList.create}">Create</h:commandLink><p/>
+ <h:commandLink action="employee/search-results?faces-redirect=true">Search All Employees</h:commandLink><p/>
+ <h:commandLink action="admin/index?faces-redirect=true">Admin</h:commandLink>
</h:form>
</ui:define>
</ui:composition>
diff --git a/employee/employee.web/src/main/webapp/images/eclipselink-logo.png b/employee/employee.web/src/main/webapp/resources/images/eclipselink-logo.png
similarity index 100%
rename from employee/employee.web/src/main/webapp/images/eclipselink-logo.png
rename to employee/employee.web/src/main/webapp/resources/images/eclipselink-logo.png
Binary files differ
diff --git a/employee/employee.web/src/main/webapp/images/eclipselink.png b/employee/employee.web/src/main/webapp/resources/images/eclipselink.png
similarity index 100%
rename from employee/employee.web/src/main/webapp/images/eclipselink.png
rename to employee/employee.web/src/main/webapp/resources/images/eclipselink.png
Binary files differ
diff --git a/employee/employee.web/src/main/webapp/template.jsf b/employee/employee.web/src/main/webapp/template.jsf
deleted file mode 100644
index cf6e9d1..0000000
--- a/employee/employee.web/src/main/webapp/template.jsf
+++ /dev/null
@@ -1,51 +0,0 @@
-
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml"
- xmlns:f="http://java.sun.com/jsf/core"
- xmlns:h="http://java.sun.com/jsf/html"
- xmlns:ui="http://java.sun.com/jsf/facelets"
- xmlns:fmt="http://java.sun.com/jstl/fmt">
-<head>
-<title><ui:insert name="title" /></title>
-<link rel="stylesheet" type="text/css" href="default.css" />
-</head>
-<body>
- <f:view>
- <h:form>
- <table width="100%">
- <tr>
- <td width="100%">
- <table width="100%">
- <tr>
- <td width="100%" valign="middle"><img
- src="images/eclipselink-logo.png" alt="EclipseLink" height="80" />
- <h1>Employee Example</h1></td>
- <td width="50" align="center"></td>
-
- </tr>
- </table>
- </td>
- </tr>
- </table>
-
- <table width="100%" class="accent">
- <tr>
- <td><h2>
- <ui:insert name="subtitle" />
- </h2></td>
- </tr>
- </table>
- <h:messages />
- </h:form>
-
- <ui:insert name="body" />
-
- <table width="100%" class="accent">
- <tr>
- <td height="10"></td>
- </tr>
- </table>
- </f:view>
-</body>
-</html>