Oracle® Application Development Framework Developer's Guide For Forms/4GL Developers 10g (10.1.3.1.0) Part Number B25947-01 |
|
|
View PDF |
In addition to having attributes that map to columns in an underlying table, your entity objects can include transient attributes that are value holders or that display values calculated in Java. This section explores a simple example of adding a FullName
transient attribute to the Users
entity object that calculates its value by concatenating the values of the FirstName
and LastName
attributes.
To add a transient attribute to an entity object:
Open the Attributes page in the Entity Object Editor and click the New... button. As shown in Figure 6-22:
Enter a name for the attribute like FullName
,
Set the Java Attribute Type like String
, and
Deselect the Persistent checkbox
If the value will be calculated, set Updateable to Never
Then click OK to create the attribute.
When you add a transient attribute and finish the Entity Object Editor, JDeveloper updates the XML component definition for the entity object to reflect the new attribute. Whereas a persistent entity association looks like this in the XML:
<Attribute Name="FirstName" IsNotNull="true" Precision="30" ColumnName="FIRST_NAME" Type="java.lang.String" ColumnType="VARCHAR2" SQLType="VARCHAR" TableName="USERS" > </Attribute>
a transient attribute's Attribute tag looks like this, with no TableName
and a ColumnName
of $none$
:
<Attribute Name="FullName" IsUpdateable="false" IsQueriable="false" IsPersistent="false" ColumnName="$none$" Type="java.lang.String" ColumnType="$none$" SQLType="VARCHAR" > </Attribute>
A transient attribute is a placeholder for a data value. If you change the Updatable property of the transient attribute to While New or Always, then the end user can enter a value for the attribute. If you want the transient attribute to display a calculated value, then you'll typically leave the Updatable property set to Never and write custom Java code that calculates the value.
After adding a transient attribute to the entity object, to make it a calculated attribute you need to:
Enable a custom entity object class on the Java page of the Entity Object Editor, choosing to generate accessor methods
Write Java code inside the accessor method for the transient attribute to return the calculated value
For example, after generating the UserImpl.java
view row class, the Java code to return its calculated value would reside in the getFullName()
method like this:
// Getter method for FullName calculated attribute in UserImpl.java public String getFullName() { // Commented out original line since we'll always calculate the value // return (String)getAttributeInternal(FULLNAME); return getFirstName()+" "+getLastName(); }
To ensure that the FullName
calculated attribute is reevaluated whenever the LastName
or FirstName
attributes might be changed by the end user, you can add one line to their respective setter methods to mark FullName
as "dirty" whenever either's value is set.
// Setting method for FirstName attribute in UserImpl.java public void setFirstName(String value) { setAttributeInternal(FIRSTNAME, value); // Notify any clients that the FullName attribute has changed populateAttribute(FULLNAME,null,true, /* send notification */ false, /* markAsChanged */ false);/* saveCopy */ }
and
public void setLastName(String value) { setAttributeInternal(LASTNAME, value); // Notify any clients that the FullName attribute has changed populateAttribute(FULLNAME,null,true, /* send notification */ false, /* markAsChanged */ false);/* saveCopy */ }