You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Kamran Kashanian (JIRA)" <de...@myfaces.apache.org> on 2010/10/11 22:15:34 UTC
[jira] Created: (TRINIDAD-1938) RowKeyPropertyModel and
RowKeyPropertyTreeModel
RowKeyPropertyModel and RowKeyPropertyTreeModel
-----------------------------------------------
Key: TRINIDAD-1938
URL: https://issues.apache.org/jira/browse/TRINIDAD-1938
Project: MyFaces Trinidad
Issue Type: Improvement
Components: Components
Affects Versions: 2.0.0.3-core
Environment: All
Reporter: Kamran Kashanian
By default, when Java Lists/Arrays are used as models in Trinidad table/tree/treeTable components, they are wrapped in a SortableModel instance.
The problem with SortableModel is that it uses row indexes as row keys. This makes SortableModel immutable and insert/delete operations in the underlying List/array can cause problems. For example, indexes shift after insert/delete operations and can cause problems if the component is holding on to row keys in SelectedRowKey/DisclosedRowKey sets.
The proposal is to add row key based CollectionModel/TreeModels which avoid using indexes as row keys.
Attaching a patch for a RowKeyPropertyModel and a RowKeyPropertyTreeModel. RowKeyPropertyModel takes a rowKeyProperty name which identifies the unique row key in each model row by name. The setRowKey/getRowKey etc APIs use the rowKeyProperty to reference the row key attribute.
One drawback with the default implementation of setRowKey API in RowKeyPropertyModel is that it is inefficient and does a linear search through the model to find the row with the given row key. The search can be optimized in subclasses for specific model implementations.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
Re: [jira] Created: (TRINIDAD-1938) RowKeyPropertyModel and RowKeyPropertyTreeModel
Posted by Kamran Kashanian <ka...@gmail.com>.
Blake,
There are no API changes, the proposal is to add a couple of row key based
models to org.apache.myfaces.trinidad.model:
1) RowKeyPropertyModel which extends SortableModel and uses row keys
instead of indexes:
package org.apache.myfaces.trinidad.model;
/**
* Creates a CollectionModel whose row keys are defined by a unique data
property in the model.
*/
public class RowKeyPropertyModel extends SortableModel
{
/**
* Creates a RowKeyPropertyModel.
*
* @param model The underlying model. If necessary, this will be converted
into a {@link DataModel}
* @param rowKeyProperty The property by which the row key can be
accessed. Row key value must be unique
*/
public RowKeyPropertyModel(Object model, String rowKeyProperty)
{
super(model);
_rowKeyProperty = rowKeyProperty;
}
/**
* No arg constructor for use as a managed-bean.
* Must call {@link #setWrappedData} and {@link #setRowKeyProperty} before
using this instance.
*/
public RowKeyPropertyModel()
{
super();
}
/**
* Gets the row key for the current row
* @return row key or null if model is not on any row
*/
public Object getRowKey()
{
if (isRowAvailable())
{
Object rowKey = _getRowKey();
return rowKey;
}
else
{
return null;
}
}
public void setRowKey(Object key)
{
if (key == null)
{
setRowIndex(-1);
return;
}
if (getRowKey() != null && getRowKey().equals(key))
return;
for (int i = 0; i < getRowCount(); i++)
{
setRowIndex(i);
Object prop = getRowKey();
if (key.equals(prop))
{
return;
}
}
// if we didn't find an element with a matching key,
// then don't make any rows current
setRowIndex(-1);
}
/**
* Gets the row key property name for this model
* @return row key property name
*/
public String getRowKeyProperty()
{
return _rowKeyProperty;
}
/**
* Sets the row key property for this model
* @param rowKeyProperty row key property to set
*/
public void setRowKeyProperty(String rowKeyProperty)
{
_rowKeyProperty = rowKeyProperty;
}
/**
* gets the row key for the given row by resolving the _rowKeyProperty
* @param row row to retrieve the row key for
* @return row key value
*/
protected Object getRowKey(Object row)
{
return __resolveProperty(row, _rowKeyProperty);
}
/**
* gets the row key for current row by resolving the _rowKeyProperty
* @return
*/
private Object _getRowKey()
{
Object data = getRowData();
return __resolveProperty(data, _rowKeyProperty);
}
private String _rowKeyProperty;
}
2) RowKeyPropertyTreeModel which extends ChildPropertyTreeModel and wraps
each child model with a RowKeyPropertyModel:
package org.apache.myfaces.trinidad.model;
/**
* A subclass of {@link ChildPropertyTreeModel} that supports row keys by
creating
* {@link RowKeyPropertyModel}(s) for its child models.
*
* Ooverrides the protected createChildModel method in {@link
ChildPropertyTreeModel} so that it can instantiate
* RowKeyPropertyModels as it encounters child data.
*/
public class RowKeyPropertyTreeModel
extends ChildPropertyTreeModel
{
/**
* Creates a RowKeyPropertyTreeModel
*
* @param model The underlying model. This will be converted into a {@link
DataModel}
* @param childProperty The property by which the child data can be
accessed.
* @param rowKeyProperty The property by which the row key can be
accessed.
*/
public RowKeyPropertyTreeModel(Object model, String childProperty,
String rowKeyProperty)
{
super (new RowKeyPropertyModel(model, rowKeyProperty), childProperty);
_rowKeyProperty = rowKeyProperty;
}
/**
* No-arg constructor for use with managed-beans.
* Must call the {@link #setChildProperty},
* {@link #setWrappedData} and {@link #setRowKeyProperty} methods after
constructing this instance.
*/
public RowKeyPropertyTreeModel()
{
super();
}
/**
* Overrides ChildPropertyTreeModel.createChildModel().
* Converts childData into a RowKeyPropertyModel.
*
* @param childData the data to convert. This can be a List or array.
*/
@Override
protected CollectionModel createChildModel(Object childData)
{
CollectionModel model =
new RowKeyPropertyModel(childData, _rowKeyProperty);
model.setRowIndex(-1);
return model;
}
/**
* Gets the row key property name for this model
* @return row key property name
*/
public String getRowKeyProperty()
{
return _rowKeyProperty;
}
/**
* Sets the row key property for this model
* @param rowKeyProperty row key property to set
*/
public void setRowKeyProperty(String rowKeyProperty)
{
_rowKeyProperty = rowKeyProperty;
}
private String _rowKeyProperty = null;
}
Thanks
Kamran
On Mon, Oct 11, 2010 at 4:07 PM, Blake Sullivan
<bl...@oracle.com>wrote:
>
> Kamran,
>
> You are really supposed to send the javasdoc for the public apis. We
> shouldn't have to take your patch apart in order to comment on it. The
> e-mail is also missing the [api] tag.
>
> -- Blake Sullivan
>
>
>
> On 10/11/10 2:57 PM, Kamran Kashanian wrote:
>
> To clarify https://issues.apache.org/jira/browse/TRINIDAD-1938 ...
>
> The proposal is to add two new model implementations
> in org.apache.myfaces.trinidad.model package:
>
> 1) org.apache.myfaces.trinidad.model.RowKeyPropertyModel
> 2) org.apache.myfaces.trinidad.model.RowKeyPropertyTreeModel
>
>
> RowKeyPropertyModel extends SortableModel and uses row keys (identified
> by a property in each row) instead of indexes.
> RowKeyPropertyTreeModel extends ChildPropertyTreeModel and wraps each child
> model with a RowKeyPropertyModel.
>
> For implementation details for each model please refer to the patch
>
> Thanks
> Kamran
>
>
> On Mon, Oct 11, 2010 at 2:15 PM, Kamran Kashanian (JIRA) <
> dev@myfaces.apache.org> wrote:
>
>> RowKeyPropertyModel and RowKeyPropertyTreeModel
>> -----------------------------------------------
>>
>> Key: TRINIDAD-1938
>> URL: https://issues.apache.org/jira/browse/TRINIDAD-1938
>> Project: MyFaces Trinidad
>> Issue Type: Improvement
>> Components: Components
>> Affects Versions: 2.0.0.3-core
>> Environment: All
>> Reporter: Kamran Kashanian
>>
>>
>> By default, when Java Lists/Arrays are used as models in Trinidad
>> table/tree/treeTable components, they are wrapped in a SortableModel
>> instance.
>>
>> The problem with SortableModel is that it uses row indexes as row keys.
>> This makes SortableModel immutable and insert/delete operations in the
>> underlying List/array can cause problems. For example, indexes shift after
>> insert/delete operations and can cause problems if the component is holding
>> on to row keys in SelectedRowKey/DisclosedRowKey sets.
>>
>> The proposal is to add row key based CollectionModel/TreeModels which
>> avoid using indexes as row keys.
>>
>> Attaching a patch for a RowKeyPropertyModel and a RowKeyPropertyTreeModel.
>> RowKeyPropertyModel takes a rowKeyProperty name which identifies the
>> unique row key in each model row by name. The setRowKey/getRowKey etc APIs
>> use the rowKeyProperty to reference the row key attribute.
>>
>> One drawback with the default implementation of setRowKey API in
>> RowKeyPropertyModel is that it is inefficient and does a linear search
>> through the model to find the row with the given row key. The search can be
>> optimized in subclasses for specific model implementations.
>>
>>
>> --
>> This message is automatically generated by JIRA.
>> -
>> You can reply to this email to add a comment to the issue online.
>>
>>
>
>
Re: [jira] Created: (TRINIDAD-1938) RowKeyPropertyModel and RowKeyPropertyTreeModel
Posted by Blake Sullivan <bl...@oracle.com>.
Kamran,
You are really supposed to send the javasdoc for the public apis. We
shouldn't have to take your patch apart in order to comment on it. The
e-mail is also missing the [api] tag.
-- Blake Sullivan
On 10/11/10 2:57 PM, Kamran Kashanian wrote:
> To clarify https://issues.apache.org/jira/browse/TRINIDAD-1938 ...
>
> The proposal is to add two new model implementations
> in org.apache.myfaces.trinidad.model package:
>
> 1) org.apache.myfaces.trinidad.model.RowKeyPropertyModel
> 2) org.apache.myfaces.trinidad.model.RowKeyPropertyTreeModel
>
>
> RowKeyPropertyModel extends SortableModel and uses row keys
> (identified by a property in each row) instead of indexes.
> RowKeyPropertyTreeModel extends ChildPropertyTreeModel and wraps each
> child model with a RowKeyPropertyModel.
>
> For implementation details for each model please refer to the patch
>
> Thanks
> Kamran
>
>
> On Mon, Oct 11, 2010 at 2:15 PM, Kamran Kashanian (JIRA)
> <dev@myfaces.apache.org <ma...@myfaces.apache.org>> wrote:
>
> RowKeyPropertyModel and RowKeyPropertyTreeModel
> -----------------------------------------------
>
> Key: TRINIDAD-1938
> URL:
> https://issues.apache.org/jira/browse/TRINIDAD-1938
> Project: MyFaces Trinidad
> Issue Type: Improvement
> Components: Components
> Affects Versions: 2.0.0.3-core
> Environment: All
> Reporter: Kamran Kashanian
>
>
> By default, when Java Lists/Arrays are used as models in Trinidad
> table/tree/treeTable components, they are wrapped in a
> SortableModel instance.
>
> The problem with SortableModel is that it uses row indexes as row
> keys. This makes SortableModel immutable and insert/delete
> operations in the underlying List/array can cause problems. For
> example, indexes shift after insert/delete operations and can
> cause problems if the component is holding on to row keys in
> SelectedRowKey/DisclosedRowKey sets.
>
> The proposal is to add row key based CollectionModel/TreeModels
> which avoid using indexes as row keys.
>
> Attaching a patch for a RowKeyPropertyModel and a
> RowKeyPropertyTreeModel. RowKeyPropertyModel takes a
> rowKeyProperty name which identifies the unique row key in each
> model row by name. The setRowKey/getRowKey etc APIs use the
> rowKeyProperty to reference the row key attribute.
>
> One drawback with the default implementation of setRowKey API in
> RowKeyPropertyModel is that it is inefficient and does a linear
> search through the model to find the row with the given row key.
> The search can be optimized in subclasses for specific model
> implementations.
>
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>
Re: [jira] Created: (TRINIDAD-1938) RowKeyPropertyModel and RowKeyPropertyTreeModel
Posted by Kamran Kashanian <ka...@gmail.com>.
To clarify https://issues.apache.org/jira/browse/TRINIDAD-1938 ...
The proposal is to add two new model implementations
in org.apache.myfaces.trinidad.model package:
1) org.apache.myfaces.trinidad.model.RowKeyPropertyModel
2) org.apache.myfaces.trinidad.model.RowKeyPropertyTreeModel
RowKeyPropertyModel extends SortableModel and uses row keys (identified by a
property in each row) instead of indexes.
RowKeyPropertyTreeModel extends ChildPropertyTreeModel and wraps each child
model with a RowKeyPropertyModel.
For implementation details for each model please refer to the patch
Thanks
Kamran
On Mon, Oct 11, 2010 at 2:15 PM, Kamran Kashanian (JIRA) <
dev@myfaces.apache.org> wrote:
> RowKeyPropertyModel and RowKeyPropertyTreeModel
> -----------------------------------------------
>
> Key: TRINIDAD-1938
> URL: https://issues.apache.org/jira/browse/TRINIDAD-1938
> Project: MyFaces Trinidad
> Issue Type: Improvement
> Components: Components
> Affects Versions: 2.0.0.3-core
> Environment: All
> Reporter: Kamran Kashanian
>
>
> By default, when Java Lists/Arrays are used as models in Trinidad
> table/tree/treeTable components, they are wrapped in a SortableModel
> instance.
>
> The problem with SortableModel is that it uses row indexes as row keys.
> This makes SortableModel immutable and insert/delete operations in the
> underlying List/array can cause problems. For example, indexes shift after
> insert/delete operations and can cause problems if the component is holding
> on to row keys in SelectedRowKey/DisclosedRowKey sets.
>
> The proposal is to add row key based CollectionModel/TreeModels which avoid
> using indexes as row keys.
>
> Attaching a patch for a RowKeyPropertyModel and a RowKeyPropertyTreeModel.
> RowKeyPropertyModel takes a rowKeyProperty name which identifies the
> unique row key in each model row by name. The setRowKey/getRowKey etc APIs
> use the rowKeyProperty to reference the row key attribute.
>
> One drawback with the default implementation of setRowKey API in
> RowKeyPropertyModel is that it is inefficient and does a linear search
> through the model to find the row with the given row key. The search can be
> optimized in subclasses for specific model implementations.
>
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>
[jira] Commented: (TRINIDAD-1938) RowKeyPropertyModel and
RowKeyPropertyTreeModel
Posted by "Max Starets (JIRA)" <de...@myfaces.apache.org>.
[ https://issues.apache.org/jira/browse/TRINIDAD-1938?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12922563#action_12922563 ]
Max Starets commented on TRINIDAD-1938:
---------------------------------------
+1 on promoting these classes to org.apache.myfaces.trinidad.model
I think I would add asserts for (rowKeyProperty != null ) before each __resolveProperty call.
> RowKeyPropertyModel and RowKeyPropertyTreeModel
> -----------------------------------------------
>
> Key: TRINIDAD-1938
> URL: https://issues.apache.org/jira/browse/TRINIDAD-1938
> Project: MyFaces Trinidad
> Issue Type: Improvement
> Components: Components
> Affects Versions: 2.0.0.3-core
> Environment: All
> Reporter: Kamran Kashanian
> Attachments: rowkeymodel.patch
>
>
> By default, when Java Lists/Arrays are used as models in Trinidad table/tree/treeTable components, they are wrapped in a SortableModel instance.
> The problem with SortableModel is that it uses row indexes as row keys. This makes SortableModel immutable and insert/delete operations in the underlying List/array can cause problems. For example, indexes shift after insert/delete operations and can cause problems if the component is holding on to row keys in SelectedRowKey/DisclosedRowKey sets.
> The proposal is to add row key based CollectionModel/TreeModels which avoid using indexes as row keys.
> Attaching a patch for a RowKeyPropertyModel and a RowKeyPropertyTreeModel. RowKeyPropertyModel takes a rowKeyProperty name which identifies the unique row key in each model row by name. The setRowKey/getRowKey etc APIs use the rowKeyProperty to reference the row key attribute.
> One drawback with the default implementation of setRowKey API in RowKeyPropertyModel is that it is inefficient and does a linear search through the model to find the row with the given row key. The search can be optimized in subclasses for specific model implementations.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (TRINIDAD-1938) RowKeyPropertyModel and
RowKeyPropertyTreeModel
Posted by "Andrew Robinson (JIRA)" <de...@myfaces.apache.org>.
[ https://issues.apache.org/jira/browse/TRINIDAD-1938?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Andrew Robinson updated TRINIDAD-1938:
--------------------------------------
Resolution: Fixed
Fix Version/s: 2.0.0.3-core
Status: Resolved (was: Patch Available)
thanks to Kamran for the patch
> RowKeyPropertyModel and RowKeyPropertyTreeModel
> -----------------------------------------------
>
> Key: TRINIDAD-1938
> URL: https://issues.apache.org/jira/browse/TRINIDAD-1938
> Project: MyFaces Trinidad
> Issue Type: Improvement
> Components: Components
> Affects Versions: 2.0.0.3-core
> Environment: All
> Reporter: Kamran Kashanian
> Fix For: 2.0.0.3-core
>
> Attachments: rowkeymodel1.patch
>
>
> By default, when Java Lists/Arrays are used as models in Trinidad table/tree/treeTable components, they are wrapped in a SortableModel instance.
> The problem with SortableModel is that it uses row indexes as row keys. This makes SortableModel immutable and insert/delete operations in the underlying List/array can cause problems. For example, indexes shift after insert/delete operations and can cause problems if the component is holding on to row keys in SelectedRowKey/DisclosedRowKey sets.
> The proposal is to add row key based CollectionModel/TreeModels which avoid using indexes as row keys.
> Attaching a patch for a RowKeyPropertyModel and a RowKeyPropertyTreeModel. RowKeyPropertyModel takes a rowKeyProperty name which identifies the unique row key in each model row by name. The setRowKey/getRowKey etc APIs use the rowKeyProperty to reference the row key attribute.
> One drawback with the default implementation of setRowKey API in RowKeyPropertyModel is that it is inefficient and does a linear search through the model to find the row with the given row key. The search can be optimized in subclasses for specific model implementations.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (TRINIDAD-1938) RowKeyPropertyModel and
RowKeyPropertyTreeModel
Posted by "Kamran Kashanian (JIRA)" <de...@myfaces.apache.org>.
[ https://issues.apache.org/jira/browse/TRINIDAD-1938?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Kamran Kashanian updated TRINIDAD-1938:
---------------------------------------
Status: Patch Available (was: Open)
> RowKeyPropertyModel and RowKeyPropertyTreeModel
> -----------------------------------------------
>
> Key: TRINIDAD-1938
> URL: https://issues.apache.org/jira/browse/TRINIDAD-1938
> Project: MyFaces Trinidad
> Issue Type: Improvement
> Components: Components
> Affects Versions: 2.0.0.3-core
> Environment: All
> Reporter: Kamran Kashanian
> Attachments: rowkeymodel.patch
>
>
> By default, when Java Lists/Arrays are used as models in Trinidad table/tree/treeTable components, they are wrapped in a SortableModel instance.
> The problem with SortableModel is that it uses row indexes as row keys. This makes SortableModel immutable and insert/delete operations in the underlying List/array can cause problems. For example, indexes shift after insert/delete operations and can cause problems if the component is holding on to row keys in SelectedRowKey/DisclosedRowKey sets.
> The proposal is to add row key based CollectionModel/TreeModels which avoid using indexes as row keys.
> Attaching a patch for a RowKeyPropertyModel and a RowKeyPropertyTreeModel. RowKeyPropertyModel takes a rowKeyProperty name which identifies the unique row key in each model row by name. The setRowKey/getRowKey etc APIs use the rowKeyProperty to reference the row key attribute.
> One drawback with the default implementation of setRowKey API in RowKeyPropertyModel is that it is inefficient and does a linear search through the model to find the row with the given row key. The search can be optimized in subclasses for specific model implementations.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.