|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
The common interface implemented by all Bebop components. During its lifetime, a component receives the following calls from the containing page.
register(Page)
is called to register
state parameters that need to be preserved between requests to
the same page.
register(Form, FormModel)
is called if
the component is contained
in a Form
or FormSection
. Typically, only form
widgets like text controls have parameters that need to be
registered with the FormSection
.
lock
is called to lock the component and
inform it that no further structural modifications will be
made.
respond
is called.
generateXML
is
called to produce XML output that will be transformed by the
templating system.
A component can be either visible or invisible. Invisible components do not produce any output and containers should be careful to completely hide their presence. The visibility of a component can be influenced in a number of ways:
Page
, it is
visible.Page.setVisibleDefault
during setup of the page.setVisible
. The Page
makes sure that the visibility of components is
preserved across repeated requests to the same page.
Each component supports a few standard attributes that are copied through to the output when producing either HTML or XML output. These attributes are not used internally in any way, and setting them is entirely optional.
The standard attributes appear in the output as attributes in the element generated from this component. They correspond directly to properties with setters and getters. The standard attributes are as folows.
Attribute | Java property | Purpose |
---|---|---|
id |
getIdAttr /setIdAttr
|
Use to uniquely identify a component within the page. Uniqueness is not enforced. The id attribute allows stylesheet designers to access individual components. |
class | getClassAttr() /setClassAttr(String) |
Use as the generic name for a component. For example, if you have a UserInfoDisplay component, the class attribute can be used to name the component "UserInfoDisplay" so that a generic template rule can style all UserInfoDisplay components. |
style | getStyleAttr /setStyleAttr |
Use to add CSS style to an individual element. |
When extending any Component
, honor the
Lockable contract indicated by extends
. Beware that member variables
are not inherently threadsafe, because you may be circumventing
the contract. For variables that might be different for each
request, use Lockable
RequestLocal
. If you must add member
variables in the derived class, as a minimum be sure to safeguard
any write access to instance variables with Assert.assertNotLocked(com.arsdigita.util.Lockable)
.
Field Summary | |
static String |
BEBOP_XML_NS
The XML namespace used by all the Bebop components. |
static String |
CLASS
The name for the class attribute. |
static String |
ID
The name for the ID attribute. |
static String |
ON_CLICK
The onClick event. |
static String |
STYLE
The name for the style attribute. |
static String |
versionId
|
Method Summary | |
Iterator |
children()
Returns an iterator over the children of this component. |
void |
generateXML(PageState state,
Element parent)
Adds a DOM subtree representing this component under the given parent node. |
String |
getClassAttr()
Gets the class attribute. |
String |
getIdAttr()
Gets the id attribute. |
String |
getKey()
Retrieves the programmer-supplied key. |
String |
getStyleAttr()
Gets the style attribute. |
boolean |
isVisible(PageState state)
Determines whether the component is visible in the request represented by state . |
void |
register(Form f,
FormModel m)
Registers form parameters with the form model for this form. |
void |
register(Page p)
Registers state parameters for the page with its model. |
void |
respond(PageState state)
Responds to the request. |
void |
setClassAttr(String theClass)
Sets the class attribute. |
void |
setIdAttr(String id)
Sets the id attribute. |
Component |
setKey(String key)
Supplies a key for making parameter names unique. |
void |
setStyleAttr(String style)
Sets the style attribute. |
void |
setVisible(PageState state,
boolean v)
Changes the visibility of the component. |
Methods inherited from interface com.arsdigita.util.Lockable |
isLocked, lock |
Field Detail |
public static final String versionId
public static final String BEBOP_XML_NS
public static final String CLASS
setClassAttr(String)
,
Standard Attributes,
Constant Field Valuespublic static final String STYLE
setStyleAttr(String)
,
Standard Attributes,
Constant Field Valuespublic static final String ID
setIdAttr(java.lang.String)
,
Standard Attributes,
Constant Field Valuespublic static final String ON_CLICK
Method Detail |
public void generateXML(PageState state, Element parent)
Adds a DOM subtree representing this component under the given
parent node. Uses the request values stored in state
.
state
- represents the current requestparent
- the node under which the DOM subtree should be addedpublic void respond(PageState state) throws javax.servlet.ServletException
Responds to the request. This method is only called if the request
was made from a link or form that the component put on the page in the
PageState.stateAsURL()
previous request.
No output should be generated on the HTTP response. The component
can store intermediate results in the state
by calling
setAttribute
.
This method is called before any output is printed to the HTTP response so that the component can forward to a different page and thereby commit the response.
state
- represents the current request
javax.servlet.ServletException
public Iterator children()
null
) iterator.
public void register(Page p)
param
would do
the following in the body of this method:
p.addComponent(this); p.addComponentStateParam(this, param);You should override this method to set the default visibility of your component:
public void register(Page p) { super.register(p); p.setVisibleDefault(childNotInitiallyShown,false); p.setVisibleDefault(anotherChild, false); }Always call
super.register
when you override
register
. Otherwise your component may
malfunction and produce errors like "Widget ... isn't
associated with any Form"
public void register(Form f, FormModel m)
form
sections
and widgets
(components that have a connection to an HTML form). Other
components can implement it as a no-op.
public String getClassAttr()
setClassAttr(String)
,
Standard Attributespublic void setClassAttr(String theClass)
theClass
- a valid XML namegetClassAttr()
public String getStyleAttr()
setStyleAttr(java.lang.String)
,
Standard Attributespublic void setStyleAttr(String style)
style
should be a valid CSS
style, because its value will be copied verbatim to the output and
appear as a style attribute in the top level XML or HTML
output element.
style
- a valid CSS style description for use in the
style attribute of an HTML tagpublic String getIdAttr()
setIdAttr(String id)
public void setIdAttr(String id)
id
should be an XML name
that is unique within the Page
in which this component is
contained. The value of id
is copied literally to the
output and not used for internal processing.
id
- a valid XML identifierpublic Component setKey(String key)
public String getKey()
public boolean isVisible(PageState state)
state
.
state
- represents the current request
true
if the component is visible in the request;
false
otherwise.setVisible
,
Description of Visibility
abovepublic void setVisible(PageState state, boolean v)
state
- represents the current requestv
- true
if the component should be visible
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |