Java Reference
In-Depth Information
} else {
customerDAO.edit(customer);
}
return "success";
}
The first thing we do in this method is to obtain the current session scoped instance
of the
Customer
managed bean by invoking
getValue()
(this method is inherited
from
com.sun.rave.web.ui.appbase.FacesBean
). This method will be used
both for updating an existing customer and for inserting a new customer to the
database, therefore we need to check the value of its
customerId
property. If it is
null
, it means we are dealing with a new customer, therefore we need to insert it
by invoking the
create()
method on the
CustomerFacade
session bean, otherwise
we need to invoke its
merge()
method, which will update the corresponding row
in the database. Finally we need to return a
String
to be used in the appropriate
navigation rule in
faces-config.xml
.
At this point we are ready to implement the logic to be executed when the
Cancel
button is pressed, double-clicking on this button in the
Design
window
automatically generates the action listener method.
public String cancelButton_action() {
return "cancel";
}
All we need to do in this method is simply return a
String
, which will be used to
navigate back to the
Customer Management
page when this button is pressed.
Now that we have a fully functional edit page, we need to add the remaining
functionality to the Customer List page.
Double-clicking on the
Add New
button in the
Design
window results in the action
listener method for this button being generated.
public String addNewButton_action() {
setValue("#{sessionScope.Customer}", new Customer());
return "addNew";
}
In this method we simply initialize the customer managed bean to a new instance of
our
Customer
class and return a
String
to be used for page navigation.