source code here.
Now let’s code this application in
five minutes using NetBeans and
JavaServer Faces.
1. Generate the initial NetBeans project:
a. Launch NetBeans and create a new
project.
b. From the File menu, choose New
Project.
c. From Categories, select Java Web.
d. From Projects, select Web
Application.
e. Click Next.
f. Type a project name, AuctionApp,
and click Next.
g. Make sure the Server is GlassFish
The AuctionApp is created with a
simple index.xhtml.
2. Right-click the project and select
Run.
The default page, as seen in Figure 1,
will be displayed with the simple message, “Hello from Facelets.”
3. Create the entities:
a. Right-click the AuctionApp project
and select New; then select Entity
class.
b. Type Seller in the Class Name field,
type
com.bonbhel.oracle.auctionApp
in the Package field, and click Next.
c. From the Provider and Database,
@Entity
public class Seller implements Serializable {
@One ToMany(mappedBy = "seller")
private List<Item> items;
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = Generation Type.AUTO)
private Long id;
protected String firstName;
protected String lastName;
protected String email;
COMMUNITY
JAVA IN ACTION
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
See all listings as text
ABOUT US
Figure 1
select EclipseLink (JPA 2.0)(default).
d. Choose one of the datasources
provided by NetBeans. Click Finish.
e. Repeat Step 3 for each entity.
NetBeans generates the Seller.java,
Item.java, and Bid.java files.
Now we are going to add properties in
the entities using the NetBeans wizard.
1. Open the Seller.java file, right-click
anywhere in the code, and select
Insert code.
2. Select Add property and add the
seller properties (String firstName,
String lastName, and String email).
3. Open the Item.java file and add the
item properties (String title, String
description, Double initialPrice, and
Seller seller).
4. Click the NetBeans warning to define
the entity relationship (bidirectional
ManyToOne).
This action creates a list of items in
the Seller entity.
5. Open the Bid.java file and add the
item properties (String bidderName,
Double amount, and item).
6. Click the NetBeans warning to define
the entity relationship (bidirectional
ManyToOne).
This action creates a list of bids in the
Item entity.
7. Generate the Getters and Setter,
respectively, for the list of items and
bids created in the Seller and Item
entities.
At this point, your Seller.java file will
look like Listing 1.
8. Add the RESTful capacities in the
initial NetBeans project:
a. Right-click the AuctionApp project
and select New; then select RESTful
Web Services from Entity Classes.
b. From Entity Classes, click Add all;
then click Next.
c. Two names need to be specified:
a Resource Package name such as
com.bonbhel.oracle.auctionApp
.resource and a Converter
Package name,
com.bonbhel.oracle
blog