Kamran,
I am +1 on the approach. My only comments are about the documentation.
I think that the following, terser version is more accurate
/**
* Hook called with the result of<code>createCollectionModel</code>.
* Subclasses can use this method to perform initialization after the
CollectionModel
* is fully initialized.
* Subclassers should call super before accessing any component state to
ensure
* that superclass initialization has been performed.
* @see #createCollectionModel
* @param model The model instance returned
by<code><createCollectionModel</code>
*/
protected void postCreateCollectionModel(CollectionModel model)
{
// do nothing
}
The other part is that non-final subclasses need to document whether
they require their subclassers to call super or not and this
documentation should either remind subclassers that they must call super
or document that they must look at their superclass documentation.
Requiring calls to super would be more future-proof and I have adjusted
the documentation appropriately.
The documentation form createCollectionModel should be changed as well.
Also, though unlikely, this change would require changes if a subclass
happened to be calling createCollectionModel() on its own and its
superclass moved its initialization to postCreateCollectionModel()
-- Blake Sullivan
On 8/22/10 5:30 PM, Kamran Kashanian (JIRA) wrote:
Issue with Trinidad UIXCollection class 'createCollectionModel' method
----------------------------------------------------------------------
Key: TRINIDAD-1889
URL: https://issues.apache.org/jira/browse/TRINIDAD-1889
Project: MyFaces Trinidad
Issue Type: Bug
Components: Components
Affects Versions: 2.0.0.3-core
Environment: All
Reporter: Kamran Kashanian
Attachments: uixcollection.patch
The Trinidad UIXCollection class contains an abstract method called
'createCollectionModel'. Subclasses are supposed to override this method and
use it to create a CollectionModel instance for use by the component.
Currently subclasses like UIXTable and UIXTree use 'createCollectionModel' to
get the component's 'value' attribute and wrap the object in the 'value'
attribute in a CollectionModel/TreeModel instance (if necessary) .
UIXTable and UIXTree also perform other initializations in
'createCollectionModel. For example, SelectedRowKeys and DisclosedRowKeys
sets are initialized in 'createCollectionModel'.
The issue with the current design is that the component's reference to the
CollectionModel is not fully initialized until 'createCollectionModel' returns
a CollectionModel instance and the resulting model is stored in the component's
state by UIXCollection.
So for example, UIXTable and UIXTree should not be performing initialization
of component's attribute that depend on a fully initialized CollectionModel
reference inside the 'createCollectionModel'.
The SelectedRowKeys and DisclosedRowKeys sets require a fully initialized
CollectionModel before they should be referenced. Otherwise if these
attributes are EL-bound and a backing bean logic references the CollectionModel
in the getter method for SelectedRowKeys and DisclosedRowKeys, the backing
bean may get an uninitialized CollectionModel reference.
The proposal is to add the following method to UIXCollection:
/**
* Called after<code>createCollectionModel</code> when the model is fully
initialized
* Subclasses can use this method to perform initialization of component
attributes
* that should occur only after the CollectionModel is fully initialized in
*<code>createCollectionModel</code>
* This is a do nothing implementation to avoid breaking existing code
* * @see #createCollectionModel
* @param model
*/
protected void postCreateCollectionModel(CollectionModel model)
{
// do nothing
}
This method will be called by UIXCollection after 'createCollectionModel'
returns and the component's reference to the CollectionModel is fully
initialized. Any initialization of model-dependent attributes can then occur
in 'postCreateCollectionModel'