Tutorials to .com

Tutorials to .com » Jsp » Tapestry-hivemind » Tapestry Developer's Guide (5)

Tapestry Developer's Guide (5)

Print View , by: iSee ,Total views: 10 ,Word Count: 831 ,Date: Thu, 16 Apr 2009 Time: 11:37 PM

JavaBeans and Properties chapter

tapestry framework JavaBeans and JavaBeans properties based on use. This section these concepts will be briefly recalled. More in-depth discussion can be found in the java Tutorial.

2.1 JavaBeans

When the type of java object is not known exactly when, JavaBeans framework is to manipulate a form of Java objects. Java objects such as the exact type of the unknown, they allow them the ability to work together is very strong. This reflects the Java language as a high degree of dynamic flexibility, so that the underlying language in the examples, such as c + + is impossible.

Many components of the framework is based on the JavaBeans framework, including Java's AWT and Swing's GUI libraries, as well as Tapestry. View is that, in accordance with the number of naming and coding habits, a new type of "insert" a framework is possible, when the framework is created, these categories have not even written. Tapestry is in accordance with the terms, which are used to allow components to create a new Tapestry.

Any Java object can operate as a JavaBean; it is just to follow certain naming conventions (the next part of discussion). Where the framework needs to create a new instance of a class of cases, for example, when the Tapestry components to create a new instance, Java must implement a public, non-parameter constructor (it can also achieve another constructor ). Java Reflection API allows a class to visit Tapestry methods, properties, and constructors.

2.2 JavaBeans Properties

For Tapestry, JavaBeans properties of the concept of the center. Tapestry framework allows JavaBeans to any number of objects as named properties of a collection to treat. Tapestry frequently named attribute from the read value, and occasionally will write the value of these properties have been named. Here refers to the attribute (property) is different from the nature of (attribute) ... although, often, each attribute (property) by a character (attribute) support. For Tapestry, and the Reflection API, a set of attributes is the object of public methods. Visit the properties involved in these methods call one of the.
2.1 JavaBeans getter method example
public type getName ()
(
...
)
2.2 JavaBeans setter method example
public void setName (type value)
(
...
)
Attribute can be read-only or write only (that is, it may achieve one of the two methods). Type can be scalar type (Boolean, integer, etc.) or any Java type.
Note naming; attribute the name of the first letters in the get or set back is the capital. JavaBeans property name and attributes for the method name is case-sensitive. When the name is, only the first letter of the acronym, the existence of a special case; This is done by two or more capital letters (or set up later) to identify; In this case, the attribute name is not the first letter converted to lowercase.
As a special case, a boolean property getter method for the use of an alias:
Examples 2.3. JavaBeans getter method (boolean)
public boolean isName ()
(
...
)
Although realization is a normal instance variables or set up, but the more complicated option is possible. One way is to delay evaluation, that is, expensive calculus was postponed until the actual value is necessary,
For example: 2.4 examples. JavaBeans properties evaluation of delay
public List userNames = null;

/ **
* Returns a List of user names obtained from the database.
*
** /

public List getUserNames ()
(
if (userNames == null)
userNames = fetchUserNamesFromDatabase ();

return userNames;
)
Here, the first method is called, expensive database "check" command occurred. Return value from the database, and then were stored in the cache for the latest call. Another common attribute is a comprehensive style. Here, there is no real character (attribute), in calculating the total value. One of its frequent use is to avoid a null pointer in the event of error.
Examples 2.5. JavaBeans properties of integrated
/ **
* Returns the name of the company's account representative, if
* If the company has one, or null otherwise.
*
** /

public String getAccountRepName ()
(
AccountRep rep = company.getAccountRep ();

if (rep == null)
return null;

return rep.getName ();
)
This example to create an integrated property, accountRepName.


tapestry & hivemind Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.