Welcome!

Eclipse Authors: Pat Romanski, Elizabeth White, Liz McMillan, David H Deans, JP Morgenthal

Related Topics: Open Source Cloud, Java IoT, Eclipse, Recurring Revenue

Open Source Cloud: Article

Developing a Master-Detail View

Using Eclipse, Spring, the EclipseLink Java Persistence API, & JavaServer Faces - Part 1

Java Developer Magazine on Ulitzer

This tutorial provides step-by-step instructions for creating a Web application that uses the Java Persistence API (JPA) version 2.0 with Oracle WebLogic Server 11g Release 1, Spring, EclipseLink, JavaServer Faces (JSF), and Oracle Database, Express Edition. You will develop this application using Oracle Enterprise Pack for Eclipse 11g Release 1, Patchset 1 (11.1.1.3). During the process of creating this application, you'll also get a sneak peek at planned enhancements to the Eclipse Web Tools Platform.

Application Description
The Web application you will develop in this tutorial is designed for a company that sells a variety of products. The application will maintain a list of products for sale as well as a list of customers who placed orders.

In this tutorial, you will develop modules for the Web application. The Add Customer module will add a customer to the database. The View Orders module will display a list of customers who have placed orders, as well as an overview of each order.

Application Components
The following software components are separate downloads; they are not generated by the tool during this tutorial and do not replace generated files in some cases.

Oracle SQL scripts:

  • SalesDB.sql: Oracle SQL file for the SalesDB database. This script creates the tables and populates the database. You will need to create this schema and a database user with connect and resource permission on your local Oracle Database, Express Edition 10g.

Spring beans:

  • SpringCustomerManagedBean: Queries and updates a customer file using generated Spring service beans
  • SpringCustomerListManagedBean: Ensures that all customer files are using generated Spring service beans

HTML and CSS files:

  • addCustomer.jsp: Provides a form to add a new customer file and sends a request to the addCustomer( ) method
  • viewAllCustomers.jsp: Displays a complete list of customers and provides facility to view the orders of specific customers
  • viewOrders.jsp: Displays a list of orders placed by specific customers
  • stylesheet.css: CSS file to customize appearance of JSP pages

Backing bean class:

  • CustomerManagedBean.java: Contains action methods that are responsible for adding the customer to the data store and retrieving orders of a specific customer

Other files:

  • MessageFactory.java: Retrieves localized messages from the application resource file
  • application.properties: Contains a series of keywords and values
  • faces.config.xml: Defines JSF components
  • web.xml: Defines Web container components
  • weblogic.xml: Defines Web container components specific to Oracle WebLogic Server

Software Requirements

Oracle Enterprise Pack for Eclipse 11g Release 1 (11.1.1.3)

Oracle WebLogic Server 11g Release 1 (10.3.2)

Oracle Database, Express Edition 10g

Step 1. Set Up Web Project and Connect to Database
Time to complete this step: 15 minutes

In this step, you will create a new Web project and connect to a database. A Web Project is an Eclipse Java project that contains the source code, Web pages, images, resources, and configuration files for building a Web application.

Launch Oracle Enterprise Pack for Eclipse
Double click your Eclipse icon, or, from the command line, navigate to your eclipse installation and run eclipse.exe. Close the welcome screen, and open the JPA perspective from the Window > Open Perspective > Other... > JPA menu.

Define a target runtime
To define a target runtime, click Window > Preferences > Server > Runtime Environments and choose Add...

Choose the Oracle > Oracle WebLogic Server 11gR1 and click next.

Specify the path to your C:/<middleware home>/wlserver_10.3 directory and click finish. Then click OK in the preferences window.

The tasks in this step are:

Create the oepe-jpa-tutorial project

  1. Right click in the Project Explorer and choose New > Dynamic Web Project

  1. Name the project oepe-jpa-tutorial. The tutorial code expects this name. Then click Modify.. as shown below.

  1. Edit the project's facet configuration by clicking modify and configuring the facet dialog as shown below. Make sure that the facet choices match the screenshot below: JSF 1.1, Java 5.0, JPA 1.0, EclipseLink 1.0, Dynamic Web Module 2.4. Note that Java 5.0 is *not* a default option. Then click OK and Next.

  1. Click Next and accept the default Java settings.

  1. Leave Content Directory and Context root with default values. Click Next.

  1. Now you configure the JPA Facet. Ensure that EclipseLink1.1.x is chosen as the platform. Then add a database connection by clicking Add connection....

  1. Choose the Oracle Database Connection from the list and click next.

  1. Select Oracle Database10g Driver Default from the Drivers dropdown menu and configure the screen as shown below. The userID and password should match whatever you chose during the creation of the tables and the database user. Make sure to check "save password" as shown below. Click Test Connection and verify that the ping succeeds. If it does not, check your services control panel to ensure the database service and TNS listener are started. The driver URL has the form of jdbc:oracle:thin:@{host name}:1521:{db name}.

  1. Click Finish once the ping has completed successfully. Back in the JPA Facet configuration, check the option "Add driver library to build path" and then click Next.

  1. Click Next again to advance the project wizard.
  2. Now you configure the JSF Capabilities. Choose WebLogic Shared Library (MyFaces) as the JSF Implementation Library. Next, change the default path of the JSF configuration file to /WEB-INF/config/faces-config.xml.

  1. Click Finish to create the project. Eclipse will prompt you to switch to the Java Platform, Enterprise Edition (Java EE) perspective. Click "no" for the time being.

In Part 2, I will demonstrate how to browse database artifacts using Data Source Explorer.

More Stories By Pieter Humphrey

Pieter Humphrey has been at Oracle (by way of BEA Systems) for 7+ years, working in development, marketing, sales, and developer relations to advance Java technology in the enterprise. He ran the dev2dev community at BEA and continues to with work with Oracle OTN and Eclipse Foundation communities. His current role is focused on application development tools like Oracle Enterprise Eclipse Pack, Oracle Workshop for WebLogic, JDeveloper, TopLink and the ADF framework, and is a frequent speaker at industry events and workshops.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


IoT & Smart Cities Stories
The deluge of IoT sensor data collected from connected devices and the powerful AI required to make that data actionable are giving rise to a hybrid ecosystem in which cloud, on-prem and edge processes become interweaved. Attendees will learn how emerging composable infrastructure solutions deliver the adaptive architecture needed to manage this new data reality. Machine learning algorithms can better anticipate data storms and automate resources to support surges, including fully scalable GPU-c...
Machine learning has taken residence at our cities' cores and now we can finally have "smart cities." Cities are a collection of buildings made to provide the structure and safety necessary for people to function, create and survive. Buildings are a pool of ever-changing performance data from large automated systems such as heating and cooling to the people that live and work within them. Through machine learning, buildings can optimize performance, reduce costs, and improve occupant comfort by ...
The explosion of new web/cloud/IoT-based applications and the data they generate are transforming our world right before our eyes. In this rush to adopt these new technologies, organizations are often ignoring fundamental questions concerning who owns the data and failing to ask for permission to conduct invasive surveillance of their customers. Organizations that are not transparent about how their systems gather data telemetry without offering shared data ownership risk product rejection, regu...
René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a m...
Poor data quality and analytics drive down business value. In fact, Gartner estimated that the average financial impact of poor data quality on organizations is $9.7 million per year. But bad data is much more than a cost center. By eroding trust in information, analytics and the business decisions based on these, it is a serious impediment to digital transformation.
Digital Transformation: Preparing Cloud & IoT Security for the Age of Artificial Intelligence. As automation and artificial intelligence (AI) power solution development and delivery, many businesses need to build backend cloud capabilities. Well-poised organizations, marketing smart devices with AI and BlockChain capabilities prepare to refine compliance and regulatory capabilities in 2018. Volumes of health, financial, technical and privacy data, along with tightening compliance requirements by...
Predicting the future has never been more challenging - not because of the lack of data but because of the flood of ungoverned and risk laden information. Microsoft states that 2.5 exabytes of data are created every day. Expectations and reliance on data are being pushed to the limits, as demands around hybrid options continue to grow.
Digital Transformation and Disruption, Amazon Style - What You Can Learn. Chris Kocher is a co-founder of Grey Heron, a management and strategic marketing consulting firm. He has 25+ years in both strategic and hands-on operating experience helping executives and investors build revenues and shareholder value. He has consulted with over 130 companies on innovating with new business models, product strategies and monetization. Chris has held management positions at HP and Symantec in addition to ...
Enterprises have taken advantage of IoT to achieve important revenue and cost advantages. What is less apparent is how incumbent enterprises operating at scale have, following success with IoT, built analytic, operations management and software development capabilities - ranging from autonomous vehicles to manageable robotics installations. They have embraced these capabilities as if they were Silicon Valley startups.
As IoT continues to increase momentum, so does the associated risk. Secure Device Lifecycle Management (DLM) is ranked as one of the most important technology areas of IoT. Driving this trend is the realization that secure support for IoT devices provides companies the ability to deliver high-quality, reliable, secure offerings faster, create new revenue streams, and reduce support costs, all while building a competitive advantage in their markets. In this session, we will use customer use cases...