|
WebObjects 5.2 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.webobjects.appserver.WOElement | +--com.webobjects.appserver.WOComponent
WOComponent objects dynamically render web pages (or sections of pages) at runtime. They provide custom navigation and other logic for the page, provide a framework for organizing constituent objects (static and dynamic HTML elements and subcomponents), and enable the attribute bindings of dynamic elements.
The WOComponent class has many methods that have the same names as methods of
the WOApplication class. However, the scope of the WOComponent methods is
limited to a component rather than being application-wide. For example, you
can control component-definition caching on a per-component basis using
setCachingEnabled
, which has a WOApplication counterpart.
When this kind of caching is enabled for a component, the application parses
the contents of the component directory the first time the component is
requested, creates the component definition, stores this object in memory,
and restores it for subsequent requests.
WOComponent objects also respond to awake(), sleep()
and the three
request-handling methods:
takeValuesFromRequest, invokeAction
and
appendToResponse
.
You can override these methods in your compiled subclasses, and thereby
integrate your custom behavior into the request-response loop.
takeValuesFromRequest
, it forwards that message to its
subcomponents.
The WOComponent class also provides a child-parent callback mechanism to
allow a child component to communicate with its parent. In the parent's
declaration file, bind an arbitrary attribute of the child to an action
method of the parent. Then, as the last step in the child's action method,
invoke performParentAction
with the argument being the arbitrary
attribute, returning the object received back as the response page.
Stateless components cannot have state. They can have instance variables,
but the variable's content must be transient. To ensure that when the
shared instance of a component is reused by another session there are no
side effects, reset your component's instance variables by implementing
the reset
method. In your implementation of reset ,
set to null each instance variable. Note that a stateless
component's instance variables will remain valid for the duration of the phase
(takeValuesFromRequest , invokeAction , appendToResponse
);
this lets you use instance variables in the stateless
components to hold things analogous to items in a WORepetition.
Stateless components primarily save memory, but they can significantly speed
up the application as well depending on how many stateless components you
use in the application. To make a component stateless, override the
component's isStateless
method so that it returns true.
If a stateless component is needed simultaneously in separate threads, additional instances of the component are created (and later discarded) as necessary to prevent conflicts. Thus, the number of threads in which a component could be used determines the maximum number of instances of a stateless component that may be allocated at any given time.
setCachingEnabled(boolean)
,
awake()
,
sleep()
,
takeValuesFromRequest(WORequest, WOContext)
,
invokeAction(WORequest, WOContext)
,
appendToResponse(WOResponse aResponse, WOContext aContext)
,
performParentAction(String anActionName)
,
reset()
,
isStateless()
, Serialized FormInner Class Summary | |
static class |
WOComponent.Event
The WOComponent.Event class is used to time various operations at the component level. |
Inner classes inherited from class com.webobjects.foundation.NSKeyValueCoding |
NSKeyValueCoding.DefaultImplementation, NSKeyValueCoding.ErrorHandling, NSKeyValueCoding.Null, NSKeyValueCoding.UnknownKeyException, NSKeyValueCoding.Utility, NSKeyValueCoding.ValueAccessor |
Inner classes inherited from class com.webobjects.foundation.NSKeyValueCodingAdditions |
NSKeyValueCodingAdditions.DefaultImplementation, NSKeyValueCodingAdditions.Utility |
Inner classes inherited from class com.webobjects.foundation.NSValidation |
NSValidation.DefaultImplementation, NSValidation.Utility, NSValidation.ValidationException |
Fields inherited from interface com.webobjects.foundation.NSKeyValueCoding |
NullValue |
Fields inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions |
KeyPathSeparator |
Constructor Summary | |
WOComponent()
Deprecated. use WOComponent(WOContext aContext) instead. Using this constructor will slow down your application considerably. |
|
WOComponent(WOContext aContext)
WebObjects Builder archive files exist in the component directory, and this constructor initializes component variables from this archive. |
Method Summary | |
void |
appendToResponse(WOResponse aResponse,
WOContext aContext)
Forces the component to generate its interface and output it in the response's content. |
WOApplication |
application()
Returns the WOApplication object for the current application. |
void |
awake()
Invoked at the beginning of a WOComponent's involvement in a cycle of the request-response loop. |
String |
baseURL()
Returns the component URL relative to the server's document root. |
NSArray |
bindingKeys()
Returns an NSArray containing the binding keys (as String objects) for each of the WOComponent's associations. |
static boolean |
canAccessFieldsDirectly()
WOComponent's implementation of this static method returns true . |
boolean |
canGetValueForBinding(String aBindingName)
Verifies that the binding exists and that valueForBinding
will return a value. |
boolean |
canSetValueForBinding(String aBindingName)
Verifies that the binding exists and that setValueForBinding will succeed. |
Object |
clone()
Conformance to Cloneable. |
WOContext |
context()
Returns the WOContext object for the current transaction (request-response loop) |
static void |
debugString(String string)
Deprecated. debugString is no longer supported |
String |
descriptionForResponse(WOResponse aResponse,
WOContext aContext)
Records information about the component, if it is the top-level component. |
void |
ensureAwakeInContext(WOContext aContext)
Ensures that the receiver is awake in the specified context. |
String |
frameworkName()
If the component is stored in a framework, this method returns the name of that framework. |
WOResponse |
generateResponse()
Conformance to WOActionResults. |
Object |
handleQueryWithUnboundKey(String key)
Conformance to NSKeyValueCoding.ErrorHandling. |
void |
handleTakeValueForUnboundKey(Object value,
String key)
Conformance to NSKeyValueCoding.ErrorHandling. |
boolean |
hasBinding(String aBindingName)
Returns whether the component has a binding named aBindingName . |
boolean |
hasSession()
Returns whether the component is already in a session. |
WOActionResults |
invokeAction(WORequest aRequest,
WOContext aContext)
Tells the component to execute any action specified in the request. |
boolean |
isCachingEnabled()
Returns whether component definition caching is enabled for this component. |
boolean |
isEventLoggingEnabled()
Called to determine if a component wants event logging. |
boolean |
isStateless()
By default, this method returns false , indicating that state will
be maintained for instances of the receiver. |
static void |
logString(String string)
Deprecated. logString is no longer supported. |
String |
name()
Returns the name of the component, which includes a path of all directories under DOCUMENTROOT/WebObjects and is minus the ".wo"
extension. |
WOComponent |
pageWithName(String aName)
Returns a new page instance (a WOComponent object) identified by aName . |
WOComponent |
parent()
|
String |
path()
Returns the file-system path of the component. |
WOActionResults |
performParentAction(String anActionName)
Allows a subcomponent to invoke an action method of its parent component bound to the child component. |
void |
pullValuesFromParent()
Pulls binding values from the parent component. |
void |
pushValuesToParent()
Pushes binding values to the parent component. |
void |
reset()
Allows a stateless component to reset temporary references. |
WOSession |
session()
Returns the current WOSession object. |
void |
set_componentUnroll(Object anObject)
Private. |
void |
set_unroll(Object anObject)
Private. |
void |
setCachingEnabled(boolean aFlag)
Enables or disables the caching of this component's definition. |
void |
setValueForBinding(Object aValue,
String aBindingName)
Sets the value of the binding specified in the parent component. |
void |
sleep()
Invoked at the conclusion of a request-handling cycle. |
boolean |
synchronizesVariablesWithBindings()
Indicates if the push-pull of values in the parent component is enabled. |
void |
takeValueForKey(Object value,
String key)
Conformance to NSKeyValueCoding. |
void |
takeValueForKeyPath(Object value,
String keyPath)
Conformance to NSKeyValueCodingAdditions. |
void |
takeValuesFromRequest(WORequest aRequest,
WOContext aContext)
Tells the component to synchronize its variables with values from the request. |
WOElement |
template()
Returns the graph of static, dynamic elements and components that compose this component. |
static WOElement |
templateWithHTMLString(String anHTMLString,
String aDeclarationString,
NSArray aLanguageArray)
Programmatically creates a component's template. |
WOElement |
templateWithName(String aName)
Deprecated. Use template instead. |
String |
toString()
|
void |
unableToSetNullForKey(String key)
Conformance to NSKeyValueCoding.ErrorHandling. |
Object |
validateTakeValueForKeyPath(Object value,
String keyPath)
Validates (and coerces) the given value, assigning it if it is different than the current value. |
Object |
validateValueForKey(Object value,
String key)
Conformance to NSValidation. |
void |
validationFailedWithException(Throwable t,
Object value,
String keyPath)
Called when an Enterprise Object or formatter failed validation during an assignment. |
Object |
valueForBinding(String aBindingName)
Gets the value for the specified binding from the parent component. |
Object |
valueForKey(String key)
Conformance to NSKeyValueCoding. |
Object |
valueForKeyPath(String keyPath)
Conformance to NSKeyValueCodingAdditions. |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public WOComponent()
WOComponent(WOContext aContext)
public WOComponent(WOContext aContext)
WOComponent(WOContext aContext)
in compiled subclasses to perform custom
initializations; as always, first invoke super
's default constructor.aContext
- context of a transactionMethod Detail |
public void appendToResponse(WOResponse aResponse, WOContext aContext)
appendToResponse
method on the root WOElement
object of the component template, which in turn invokes appendToResponse
.
Subclasses of WOComponent can override this
method to replace or supplement the default behavior with custom logic.appendToResponse
in class WOElement
aResponse
- the HTTP response that an application returns to a Web
server to complete a cycle of the request-response loopaContext
- context of a transactioninvokeAction(WORequest aRequest, WOContext aContext)
,
takeValuesFromRequest(WORequest aRequest, WOContext aContext)
public WOApplication application()
context()
,
session()
,
WOApplication
public void awake()
ensureAwakeInContext(WOContext aContext)
,
sleep()
public String baseURL()
name()
,
path()
public NSArray bindingKeys()
public static boolean canAccessFieldsDirectly()
true
.
It indicates that key-value coding is allowed to access fields in this
object if an appropriate method is not present.true
if key can access fields directly, otherwise false
public boolean canGetValueForBinding(String aBindingName)
valueForBinding
will return a value. The default implementation just calls hasBinding(String aBindingName)
aBindingName
- binding name used when values are pushed to or
pulled from the parent componenttrue
if key gets value for binding, otherwise false
canSetValueForBinding(String aBindingName)
,
hasBinding(String aBindingName)
,
valueForBinding(String aBindingName)
public boolean canSetValueForBinding(String aBindingName)
setValueForBinding
will succeed.aBindingName
- binding name used when values are pushed to or pulled
from the parent componenttrue
if key can set value for binding, otherwise false
canGetValueForBinding(String aBindingName)
,
hasBinding(String aBindingName)
,
setValueForBinding(Object aValue, String aBindingName)
public Object clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
- when the object is
not of known formatpublic WOContext context()
application()
,
session()
,
WOContext
public static void debugString(String string)
string
- NSLog
public String descriptionForResponse(WOResponse aResponse, WOContext aContext)
This method is invoked only on the top-level response component, that is, the one representing the entire page. Components nested inside of that top-level component do not receive this method.
If a CLFF log file is kept for this application, the string returned by this method is recorded in that log file. Thus, you must ensure that the string you return can be analyzed by a CLFF-analysis tool.
aResponse
- the HTTP response that an application returns to a Web
server to complete a cycle of the request-response loopaContext
- context of a transactionWOStatisticsStore
public void ensureAwakeInContext(WOContext aContext)
ensureAwakeInContext()
if the component
was just created with pageWithName
, if it was restored from the
WebObjects page cache, or if the page will simply be returned as
the result of an action. That is, you only need to invoke this method
if you're going to invoke methods on a component that is otherwise
not awakened. If the receiving component is already awake, this
method has no effect.aContext
- context of a transactionawake()
,
pageWithName(String aName)
public String frameworkName()
NeXT_ROOT/System/Library/Frameworks/WOExtensions.framework
,
then this method returns the String "WOExtensions". If the component is not
stored in a framework, this method returns null
.WOResourceManager
public WOResponse generateResponse()
appendToResponse
on itself.generateResponse
in interface WOActionResults
appendToResponse(WOResponse, WOContext)
,
WOResponse.generateResponse()
public Object handleQueryWithUnboundKey(String key)
handleQueryWithUnboundKey
in interface NSKeyValueCoding.ErrorHandling
key
- one of the attributes of the receiver's requestNSKeyValueCoding.DefaultImplementation
,
NSKeyValueCoding.UnknownKeyException.TargetObjectUserInfoKey
,
NSKeyValueCoding.UnknownKeyException.UnknownUserInfoKey
,
NSKeyValueCoding.valueForKey(String key)
public void handleTakeValueForUnboundKey(Object value, String key)
handleTakeValueForUnboundKey
in interface NSKeyValueCoding.ErrorHandling
value
- receiver's property identified by key is set to thiskey
- one of the attributes of the receiver's requestNSKeyValueCoding.UnknownKeyException.TargetObjectUserInfoKey
,
NSKeyValueCoding.UnknownKeyException.UnknownUserInfoKey
,
NSKeyValueCoding.takeValueForKey(Object value, String key)
public boolean hasBinding(String aBindingName)
aBindingName
.
This method traverses the chain of associations to the top-level
parent, if necessary.aBindingName
- name of the bindingtrue
if the binding exists on the component
else false
canGetValueForBinding(String aBindingName)
,
canSetValueForBinding(String aBindingName)
public boolean hasSession()
hasSession
before session
.true
if the component is in a session, false
otherwisesession()
public WOActionResults invokeAction(WORequest aRequest, WOContext aContext)
invokeAction
method is propagated through the
WOElement objects of the page. The dynamic element on which the user
has acted (by, for example, clicking a button) responds by triggering the
method in the request component that is bound to the action. WOComponent's
default implementation of this method invokes invokeAction
on the
root WOElement object of the component template.invokeAction
in class WOElement
aRequest
- the requestaContext
- context of the transactionappendToResponse(WOResponse aResponse, WOContext aContext)
,
takeValuesFromRequest(WORequest aRequest, WOContext aContext)
public boolean isCachingEnabled()
true
if caching is enabled for the component, false
otherwisesetCachingEnabled(boolean flag)
,
WOApplication.isCachingEnabled()
public boolean isEventLoggingEnabled()
true
.true
if the event logging is enabled for the component, false
otherwiseWOEvent
public boolean isStateless()
false
, indicating that state will
be maintained for instances of the receiver. Overriding this method
to return true
will make the component stateless. A single instance
of each stateless component is shared between multiple sessions,
reducing the application's memory footprint.
By default, stateless components don't synchronize. So, if you override this method to return
true
and you want the component to synchronize, you must also override
synchronizesVariablesWithBindings
and return true
.
true
if this method is overidden, false
otherwisereset()
,
synchronizesVariablesWithBindings()
public static void logString(String string)
string
- NSLog
public String name()
DOCUMENTROOT/WebObjects
and is minus the ".wo"
extension. For example, "Main" is a typical component name.baseURL()
,
path()
public WOComponent pageWithName(String aName)
aName
. If aName is null, the "Main" component is returned.
If the method cannot create a valid page instance, it throws an
exception.aName
- the name of the component to be returnedWOSession.restorePageForContextID(String aContextID)
,
WOSession.savePage(WOComponent aPage)
,
WOApplication.pageWithName(String aName, WOContext aContext)
public WOComponent parent()
public String path()
/Users/auser/MyApp.woa/Resources/Main.wo
.baseURL()
,
name()
public WOActionResults performParentAction(String anActionName)
An example best illustrates this mechanism. Let's say there is
a Palette subcomponent, and this WOComponent is nested in a parent
component with a displaySelection
action method. When the
user selects an item in the palette (perhaps a color), you want
to invoke displaySelection
to show the result of the new selection
(perhaps a car in the new color). The declaration in the parent's .wod
file would look like this:
PALETTE: Palette {
selection = number;
callBack = "displaySelection";
};
The "callBack" item is an arbitrary attribute of the child component
bound in this declaration to the parent component's displaySelection
method. The performParentAction
method is used to activate this
binding. Assuming the child component has an action method called click
,
the implementation would look like this:
public WOActionResults click() { // this is the child's action
selection = "xxxx"; // some value
// now invoke the parent's action
return performParentAction(callBack);
}
anActionName
- name of the current action methodpublic void pullValuesFromParent()
synchronizesVariablesWithBindings()
returns
true
), this method causes binding values to be pulled
from the parent component.public void pushValuesToParent()
synchronizesVariablesWithBindings()
returns
true
), this method causes binding values to be pushed up
to the parent component.public void reset()
isStateless()
public WOSession session()
application()
,
context()
,
hasSession()
,
WOSession
public void setCachingEnabled(boolean aFlag)
By default, individual component definition
caching is controlled by WOApplication's global component definition caching policy.
The global policy is set according to the start-up parameter WOCachingEnabled,
or WOApplication's setCachingEnabled(boolean aFlag)
.
With it, you can turn component definition caching off globally.
You can then control caching of individual component definitions
using WOComponent's version of this method.
Note that most large applications will set the global caching to false at deployment time.
Selective caching is an especially valuable technique for
large applications where a few highly specialized components
should not be cached but re-parsed everytime they are requested.
aFlag
- flag deciding the caching of the receiving componentisCachingEnabled()
,
WOApplication.setCachingEnabled(boolean aFlag)
public void setValueForBinding(Object aValue, String aBindingName)
aBindingName
is set to aValue
in the
parent component. If the binding isn't settable, this
method throws an exception.aValue
- value of the bindingaBindingName
- name of the binding to be setWOAssociation.isValueSettableInComponent(WOComponent
aComponent)
public void set_componentUnroll(Object anObject)
anObject
- name of the current objectpublic void set_unroll(Object anObject)
anObject
- name of the current objectpublic void sleep()
awake()
public boolean synchronizesVariablesWithBindings()
false
for stateless components
(unless you override isStateless
and return true
),
and true
otherwise. Override this method to create a non-synchronizing component.false
if this method creates a non-synchronizing component, true
otherwisevalueForBinding(String aBindingName)
,
setValueForBinding(Object aValue, String aBindingName)
,
pullValuesFromParent()
,
pushValuesToParent()
,
isStateless()
public void takeValueForKey(Object value, String key)
takeValueForKey
in interface NSKeyValueCoding
key
- identifies the property to be setvalue
- the value to which the property specified by key
should be setpublic void takeValueForKeyPath(Object value, String keyPath)
takeValueForKeyPath
in interface NSKeyValueCodingAdditions
keyPath
- identifies a derived property of the receivervalue
- value to which the derived property identified by
keyPath
will be setpublic void takeValuesFromRequest(WORequest aRequest, WOContext aContext)
template()
. In this phase, each dynamic element in
the template extracts any entered data or changed state (such as
a check in a check box) associated with an attribute and assigns
the value to the component variable bound to the attribute.
Subclasses of WOComponent can override this method to
replace or supplement the default behavior with custom logic.takeValuesFromRequest
in class WOElement
aRequest
- the current request with the WOComponent objectaContext
- context of a transactionappendToResponse(WOResponse aResponse, WOContext
aContext)
,
invokeAction(WORequest aRequest, WOContext aContext)
public WOElement template()
WOElement
,
setCachingEnabled(boolean)
,
WOApplication.setCachingEnabled(boolean aFlag)
public static WOElement templateWithHTMLString(String anHTMLString, String aDeclarationString, NSArray aLanguageArray)
anHTMLString
as the HTML template contents and
aDeclarationString
as the declarations file contents, returns
(as a WOElement object) the graph of static and dynamic elements
built by parsing the HTML and declaration Strings.
You can then use the returned WOElement as a component's template.
This method is not called by WebObjectsanHTMLString
- HTML string to create the template of the componentaDeclarationString
- declaration on the template of the componentaLanguageArray
- list of languages in specific ordertemplateWithName(String aName)
public WOElement templateWithName(String aName)
template
instead.
aName
- ignoredtemplate()
public String toString()
toString
in class WOElement
public void unableToSetNullForKey(String key)
unableToSetNullForKey
in interface NSKeyValueCoding.ErrorHandling
key
- identifies the property of an objectpublic Object validateTakeValueForKeyPath(Object value, String keyPath) throws NSValidation.ValidationException
validateValueForKey
returns an exception. Returns the coerced
(assigned) value.validateTakeValueForKeyPath
in interface NSValidation
value
- the given value to be validatedkeyPath
- the key path associated with this value, identifies the property of an objectNSValidation.ValidationException
- when the key cannot be
validated by validateValueForKeyvalidateValueForKey(Object value, String key)
public Object validateValueForKey(Object value, String key) throws NSValidation.ValidationException
validateValueForKey
in interface NSValidation
value
- the given value to be validatedkey
- the key path associated with this value, identifies the property of an objectNSValidation.ValidationException
- when the key cannot be
validated by validateValueForKeyvalidateValueForKey(java.lang.Object, java.lang.String)
public void validationFailedWithException(Throwable t, Object value, String keyPath)
t
- the exception thrown during validationvalue
- the given value to be validatedkeyPath
- the key path associated with this value, identifies the property of an objectpublic Object valueForBinding(String aBindingName)
null
.aBindingName
- name of a bindingcanGetValueForBinding(String aBindingName)
,
setValueForBinding(Object aValue, String
aBindingName)
,
synchronizesVariablesWithBindings()
public Object valueForKey(String key)
valueForKey
in interface NSKeyValueCoding
key
- identifies the property of an objectkey
public Object valueForKeyPath(String keyPath)
valueForKeyPath
in interface NSKeyValueCodingAdditions
keyPath
- identifies the derived property of an objectkeyPath
|
Last updated Fri Feb 21 13:15:00 PST 2003. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |