|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.arsdigita.kernel.ui.ACSObjectSelectionModel
Loads a subclass of an ACSObject from the database. By default, uses a BigDecimal state parameter in order to store and retrieve the item id.
The getSelectedKey(PageState state)
method will return the
BigDecimal id of the currently selected object. This method
will return the id even if the object with this id does not
actually exist.
The getSelectedObject(PageState state)
method will return the
object whose id is getSelectedKey(PageState state)
. If the
object does not actually exist, the method will return null
Thus, it is possible to implement the following pattern:
Naturally, theclass MyComponent extends SimpleComponent { ACSObjectSelectionModel m_model; public MyComponent() { super(); m_model = new ACSObjectSelectionModel("item_id"); } public void register(Page p) { super.register(p); p.addComponentStateParam(this, p.getStateParameter()); } public void doSomethingUseful(PageState s) { if (m_model.isSelected(s)) { CusomACSObject obj = (CustomACSObject)m_model.getSelectedObject(state); // Do something with obj.. } } }
ACSObjectSelectionModel
could also be passed
in as a parameter in the MyComponent
constructor. In this
case, it should be up to the parent of MyComponent
to
register the model's state parameter.
Advanced Usage: The ACSObjectSelectionModel
is actually just a wrapper for a SingleSelectionModel
which maintains the currently selected object's ID as a
BigDecimal
. By default, a new
ParameterSingleSelectionModel
is wrapped in this way;
however, any SingleSelectionModel
may be wrapped.
Thus, it becomes possible to use the ACSObjectSelectionModel
even if the currently selected ID is not stored in a state parameter.
Persistence Details: The default constructor of
ACSObjectSelectionModel
will attempt to use the
DomainObjectFactory
to automatically instantiate the correct Java subclass
of ACSObject
. However, it is also possible to use an alternate constructor
in order to force the ACSObjectSelectionModel
to manually instantiate
the objects:
In this case, the model will attempt to use reflection to instantiate the correct subclass ofACSObjectSelectionModel model = new ACSObjectSelectionModel("com.arsdigita.cms.Article", "com.arsdigita.cms.Article", "item_id");
ACSObject
. In addition, the supplementary
constructor makes it possible to create new objects in the database
using the createACSObject(BigDecimal)
method.
SingleSelectionModel
,
ParameterSingleSelectionModel
Field Summary |
Fields inherited from interface com.arsdigita.kernel.ui.DomainObjectSelectionModel |
versionId |
Constructor Summary | |
ACSObjectSelectionModel(BigDecimalParameter parameter)
Construct a new ACSObjectSelectionModel . |
|
ACSObjectSelectionModel(SingleSelectionModel model)
Construct a new ACSObjectSelectionModel . |
|
ACSObjectSelectionModel(String parameterName)
Construct a new ACSObjectSelectionModel . |
|
ACSObjectSelectionModel(String javaClass,
String objectType,
BigDecimalParameter parameter)
Construct a new ACSObjectSelectionModel |
|
ACSObjectSelectionModel(String javaClass,
String objectType,
SingleSelectionModel model)
Construct a new ACSObjectSelectionModel |
|
ACSObjectSelectionModel(String javaClass,
String objectType,
String parameterName)
Construct a new ACSObjectSelectionModel |
Method Summary | |
void |
addChangeListener(ChangeListener l)
Add a change listener to the model. |
void |
clearSelection(PageState state)
Clear the selection. |
ACSObject |
createACSObject()
A utility function which creates a new object with the given ID. |
ACSObject |
createACSObject(BigDecimal id)
Deprecated. This ignores the ID since ACSObject.setID is a no-op |
Class |
getJavaClass()
|
String |
getObjectType()
|
Object |
getSelectedKey(PageState state)
Return the key that identifies the selected object. |
DomainObject |
getSelectedObject(PageState state)
Return the object which was selected and loaded from the database, using the values supplied in the page state. |
SingleSelectionModel |
getSingleSelectionModel()
|
ParameterModel |
getStateParameter()
Return the state parameter which will be used to keep track of the currently selected key. |
boolean |
isInitialized(PageState state)
Determine if the attempt to load the selected object has been made yet. |
boolean |
isSelected(PageState state)
Return true if there is a selected object. |
protected ACSObject |
loadACSObject(PageState state,
Object key)
Load the selected object for the first time. |
void |
removeChangeListener(ChangeListener l)
Remove a change listener from the model. |
void |
setSelectedKey(PageState state,
Object key)
Set the ID of the current object. |
void |
setSelectedObject(PageState state,
DomainObject object)
Select the specified object. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ACSObjectSelectionModel(BigDecimalParameter parameter)
ACSObjectSelectionModel
.
This model will produce instances of ACSObject
by automatically instantiating the correct Java subclass using
the DomainObjectFactory
.
parameter
- The state parameter which should be used to store
the object IDpublic ACSObjectSelectionModel(String parameterName)
ACSObjectSelectionModel
.
This model will produce instances of ACSObject
by automatically instantiating the correct Java subclass using
the DomainObjectFactory
.
parameterName
- The name of the state parameter which will
be used to store the object ID.public ACSObjectSelectionModel(SingleSelectionModel model)
ACSObjectSelectionModel
.
This model will produce instances of ACSObject
by automatically instantiating the correct Java subclass using
the DomainObjectFactory
.
model
- The SingleSelectionModel
which will supply
a BigDecimal
ID of the currently selected objectpublic ACSObjectSelectionModel(String javaClass, String objectType, String parameterName)
ACSObjectSelectionModel
javaClass
- The name of the Java class which represents
the object. Must be a subclass of ACSObject
. In
addition, the class must have a constructor with a single
OID
parameter.objectType
- The name of the persistence metadata object type
which represents the ACS object. In practice, will often be
the same as the javaClass.parameterName
- The name of the state parameter which will
be used to store the object ID.public ACSObjectSelectionModel(String javaClass, String objectType, BigDecimalParameter parameter)
ACSObjectSelectionModel
javaClass
- The name of the Java class which represents
the object. Must be a subclass of ACSObject
. In
addition, the class must have a constructor with a single
OID
parameter.objectType
- The name of the persistence metadata object type
which represents the ACS object. In practice, will often be
the same as the javaClass.parameter
- The state parameter which should be used to store
the object IDpublic ACSObjectSelectionModel(String javaClass, String objectType, SingleSelectionModel model)
ACSObjectSelectionModel
javaClass
- The name of the Java class which represents
the object. Must be a subclass of ACSObject
. In
addition, the class must have a constructor with a single
OID
parameter.objectType
- The name of the persistence metadata object type
which represents the ACS object. In practice, will often be
the same as the javaClass.model
- The SingleSelectionModel
which will supply
a BigDecimal
ID of the currently selected objectMethod Detail |
public void setSelectedKey(PageState state, Object key)
getSelectedObject(PageState)
is called, the object
with the specified ID will be loaded from the database.
setSelectedKey
in interface SingleSelectionModel
state
- The page statekey
- A BigDecimal
primary key for the object,
or a String representation of a BigDecimal, such as "42".public DomainObject getSelectedObject(PageState state)
null
if isSelected(state) == false
, or if the object was not found.
getSelectedObject
in interface DomainObjectSelectionModel
state
- The page state
protected ACSObject loadACSObject(PageState state, Object key)
ACSObject
whose ID is the passed-in key.
state
- the current page statekey
- the currently selected key; guaranteed to be non-null
public void setSelectedObject(PageState state, DomainObject object)
setSelectedObject
in interface DomainObjectSelectionModel
state
- The page stateobject
- The content item to setpublic boolean isInitialized(PageState state)
state
- the page state
public ACSObject createACSObject(BigDecimal id) throws javax.servlet.ServletException
ACSObjectSelectionModel
.
If no classname was supplied in the constructor, an assertion
failure will occur.
id
- The id of the new item - this is ignored and the object
will have a different id
javax.servlet.ServletException
public ACSObject createACSObject() throws javax.servlet.ServletException
ACSObjectSelectionModel
.
If no classname was supplied in the constructor, an assertion
failure will occur.
javax.servlet.ServletException
public Class getJavaClass()
public String getObjectType()
public SingleSelectionModel getSingleSelectionModel()
SingleSelectionModel
which
maintains the ID of the selected objectpublic boolean isSelected(PageState state)
true
if there is a selected object.
isSelected
in interface SingleSelectionModel
state
- represents the state of the current request
true
if there is a selected component.public Object getSelectedKey(PageState state)
getSelectedKey
in interface SingleSelectionModel
state
- the current page state
BigDecimal
ID of the currently selected
object, or null if no object is selected.public void clearSelection(PageState state)
clearSelection
in interface SingleSelectionModel
state
- the current page state.public void addChangeListener(ChangeListener l)
stateChanged
is called whenever the selected key changes.
addChangeListener
in interface SingleSelectionModel
l
- a listener to notify when the selected key changespublic void removeChangeListener(ChangeListener l)
removeChangeListener
in interface SingleSelectionModel
l
- the listener to remove.public ParameterModel getStateParameter()
BigDecimalParameter
.
getStateParameter
in interface SingleSelectionModel
SingleSelectionModel.getStateParameter()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |