Java Reference
In-Depth Information
Once we have added the managed bean to the project, we need to bind the input
fields in the data entry page to the appropriate properties in the bean. Since we
added this bean manually to faces-config.xml it does not show up on the
Property Bindings window when we right-click on the components on the Design
or Navigation windows, therefore we need to add the bindings "by hand" by editing
the JSP markup for our page.
<webuijsf:textField id="textField1" label="First Name "
<webuijsf:textField id="textField2" label="Middle Name "
<webuijsf:textField id="textField3" label="Last Name "
<webuijsf:textField id="textField4" label="Email Address "
NetBeans code completion works when adding property bindings, after
entering #{ , hitting Ctrl+Space will show a list of all managed beans in the
project. Ditto after typing the dot after the managed bean name.
Once we have created the bindings for the text fields, we need to add some logic to
be executed when the Save or Cancel buttons are clicked.
Since we will be persisting Customer objects to the database, we need to use the
CustomerFacade session bean. Therefore we need to add an instance variable of type
CustomerFacadeLocal to the EditCustomer managed bean corresponding to
our page.
private CustomerFacadeLocal customerDAO;
The @EJB annotation is used so that the class is injected at runtime, freeing us from
doing a JNDI lookup to locate it.
Double-clicking on the Save button in the Design window results in an action
listener method being created for this button. We need to replace the body of this
method to include our logic.
public String saveButton_action() {
Customer customer = (Customer) getValue("#{Customer}");
if (customer.getCustomerId() == null) {
Search WWH ::

Custom Search