Java Reference
In-Depth Information
20.
To test the application, save the EnterEmpInfoJSP source code and run it on the server.
21.
Select Display as the function and click the Submit button.
Validate that DispEmpInfoJSP is run.
22.
In the browser window click the back button, select Gross, and then click Submit.
Validate that DispEmpGrossJSP is run.
23.
Validate that DispEmpTaxAmtJSP is run when the TaxAmt function is chosen.
Java Beans
Officially, for a Java class to be declared a Java Bean it must be defined as a public class and follow a couple of
simple rules:
A.
Have a public null constructor
B.
Implement the Serializable interface
If a bean has properties, a getter and setter should be defined for each property (so that visual tools, such as RAD,
can provide easy access to the values), but it is not a requirement.
All of the visual components (buttons, text fields, etc.) are beans, and if we imported the Serializable class and
added “implements Serializable” to the Employee class's header as follows:
import java.io.Serializable;
public class Employee implements Serializable {
Employee would be defined as a bean. (Implementing Serializable makes storing an object easier and,
since beans may be stored, this is a requirement. Note that no new methods need to be coded when implementing
the Serializable interface.) You should be aware that a class does not have to implement Serializable or have
any getters or setters to be defined as a bean by RAD/WAS. The bean rules are for ease of use and standardization,
however, RAD/WAS will let you define just about any Java class as a bean. So, even though we are going to create an
Employee bean, we will not implement Serializable in Employee.
Beans may not sound like much, but server-based beans are very useful because of their “scope.” In addition,
using JSP bean tags makes creating objects, defining them as beans, and accessing their methods and properties
much easier.
JSP Bean Tags
JSP Bean tags relieve the page designer of having to understand the Java concept of instantiation (i.e., creating objects)
and the associated Java syntax to create an object. In other words, instead of creating objects and executing methods,
beans are defined and properties values are assigned and retrieved. Again, the function of the tags is very similar to
Java script statements but the syntax is much simpler.
For instance, the following JSP useBean tag creates a Java bean:
<jsp:useBean id="EmpBean" class="c9java.Employee"
scope="session">
</jsp:useBean>
 
Search WWH ::




Custom Search