|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ComponentSchema
A component schema is a special type of DataSource that describes a custom component.
Declaring a component schema for your custom component allows you to:
constructor
and xsi:type
attributes as described under
componentXML
VisualBuilder
Example of a Component Schema
It's most basic form, a component schema for a custom subclass of ListGrid called "MyListGrid" looks like this:
<DataSource serverType="component" ID="MyListGrid" inheritsFrom="ListGrid" instanceConstructor="MyListGrid"/>With this definition saved as "MyListGrid.ds.xml" in the project dataSources directory ([webroot]/shared/ds/ by default), you can now create an instance of MyListGrid with just:
<MyListGrid width="500"/>Note: you may need to restart your servlet engine/J2EE container before this example will work.
The attributes set directly on the DataSource tag have special meaning for a component schema definition:
serverType
="component" indicates this DataSource describes
a component, as opposed to a SQL table or other data provider
ID
means the tagName that will be used to create your custom
component. This must match the first component of the filename (ID="MyListGrid" means the
filename must be MyListGrid.ds.xml) and typically also matches the name of the class.
inheritsFrom
="ListGrid" inherits the ListGrid property definitions via
inheritsFrom
.
com.smartgwt.client..Class#create
should be called on to construct an instance.
VisualBuilder
to show only the fields declared in this schema in the component editor. Otherwise fields
inherited via inheritsFrom
(all the way up the chain) are also included.
VisualBuilder
to those defined in
this schema only.
VisualBuilder
to those defined in this schema only.
Declaring custom properties
Custom properties are declared via fields
as for an ordinary
DataSource
. As with ordinary DataSources, it is legal to redeclare inherited fields
in order to modify properties such as editorType
.
The following DataSourceField properties have special significance when a component schema
is used to process 'component XML'
:
type
declares the type of the field, and hence the
type of the JavaScript value your custom class will be initialized with. In order to
declare subcomponents, can be set to the name of another component (built-in or custom).
multiple
declares that the field should always be
array-valued even when only a single value is provided. Also indicates that the field name
should be used as a "wrapper tag" in the XML format for the component.
propertiesOnly
. For fields that hold
subcomponents, suppresses auto-construction to avoid autoDraw
and to allow subcomponents to be modified by their parent component before they are created
and drawn
inapplicable
indicates that an inherited
field is inapplicable in this component.
group
indicates what group the property should be
placed in when editing in Visual Builder.
xmlAttribute
: indicates this field should
serialize as an XML attribute. Note that when constructing the component from XML, either
an attribute or a subelement will continue to be accepted as means of specifying the field
value, so this property is primarily set in order to make code generated by Visual Builder
maximally compact or to make it conform to externally set standards.
Declaring Events and Actions
Events and Actions are declared via a methods array. In order for a method to be considered
an event, it needs to have a method definition in the methods array (or be publicly
documented in the SmartGWT reference) and have been added to
the class as a 'StringMethod'
via com.smartgwt.client..Class#registerStringMethods
.
In order for a method to be considered an action, it needs to have a method definition in
the methods array and have the action
property set to true
. For
example, the following is a definition of the 'hide' action available on any Canvas, as
copied from Canvas.ds.xml:
<methods> <method name="hide" title="Hide" action="true"/> </methods>For custom component actions, an array of expected parameters may be specified using the
params
attribute. Each entry in this array should have a specified type.
By doing this, you allow the visual builder to pass parameters through to actions when setting
up events that call actions (possibly on another component).
For example if you had a component with a custom action that expected to be passed a single
parameter of type ListGridRecord
you could define it as follows:
<method name="showRecordDetails" title="Show Record Details" action="true"> <params> <param type="ListGridRecord"/> <params> </method>If a user working within the visualBuilder then added ListGrid to the page and used the "+" icon to associate the
ListGrid.addRecordClickHandler(com.smartgwt.client.widgets.grid.events.RecordClickHandler)
event with this custom method, the
Visual Builder logic would automatically associate the parameters available in the fired event
(in this case recordClick
) with the expected parameters for the action to fire
by type. So the record
parameter of the event (known to be of type
ListGridRecord
) would be passed through to this custom showRecordDetails
action as the first parameter.
DataSourceField.getXmlAttribute()
,
DataSourceField.getMultiple()
,
DataSourceField.getChildTagName()
,
DataSourceField.getPropertiesOnly()
,
DataSourceField.getInapplicable()
,
DataSourceField.getGroup()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |