You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "F. Da Costa Gomez" <da...@gmail.com> on 2005/03/07 22:49:06 UTC

java.lang.UnsupportedOperationException??

Hi,

The following method is supposed to delete an object from a 
SimpleListTableDataModel. Nothing fancy one would say.
I checked the existence of o by calling getRows() in the debugger and visually 
confirming the existence of o in the model.

private void deleteRow(IRequestCycle cycle, Object o) {
  // Remove the row from the current TableDataModel
  SimpleListTableDataModel dm = ((SimpleListTableDataModel) ((SimpleTableModel) 
   getTableModel()).getDataModel());
  dm.getRows(0, dm.getRowCount()-1);
  dm.removeRow(o);
  // Remove the row from the temporary map
  _objectLinkMap.remove(o.toString());
}

Calling removeRow() with the object o however gives me the following:
java.lang.UnsupportedOperationException
Stack Trace:

     * java.util.AbstractList.remove(AbstractList.java:171)
     * java.util.AbstractList$Itr.remove(AbstractList.java:436)
     * java.util.AbstractCollection.remove(AbstractCollection.java:255)
     * 
org.apache.tapestry.contrib.table.model.simple.SimpleListTableDataModel.removeRow(SimpleListTableDataModel.java:129)
     * org.dcg.jwc.tables.DynamicTable.deleteRow(DynamicTable.java:310)

I even set a breakpoint *in* the datamodel class on the entrypoint into the 
removeRow() method. The object to be removed was indeed present in the variable 
m_arrRows that obviously contains the objects. I even went into the 
AbstractCollection where object is 'sought out' and deleted. (or rather isn't).

I'v got no idea what i'm doing wrong here so any suggestion would be welcome.

tia,

Fermin DCG


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: java.lang.UnsupportedOperationException?? (Mind Bridge?)

Posted by Fermin Da Costa Gomez <da...@gmail.com>.
Thx Paul,

Paul Ferraro wrote:
> Digging into this quickly, I think the problem is the underlying list 
> created by SimpleListTableDataModel uses Arrays.asList().
So was i.

> Unfortunately, java.util.List.remove(Object) is an optional operation, 
> and it is not implemented by the list returned by Arrays.asList() (that 
> makes sense since you cannot remove an arbitrary element of an array in 
Fair enough, i wasn't aware of that, so this would indeed explain it.

> this way).  It would seem that the constructor of 
> SimpleListTableDataModel should instead create a new list from the array 
> [e.g. ArrayList(Arrays.asList(arrRows))], so that the remove(...) 
> operation will succeed as intended.
I'm guessing the code was recently changed because this very method used to work.

> I'm no expert on the Table component, so I'd recommend you verify this 
> with Mind Bridge.
Quietly hoping he spots the thread

Fermin

> 
> F. Da Costa Gomez wrote:
> 
>> Hi,
>>
>> The following method is supposed to delete an object from a 
>> SimpleListTableDataModel. Nothing fancy one would say.
>> I checked the existence of o by calling getRows() in the debugger and 
>> visually confirming the existence of o in the model.
>>
>> private void deleteRow(IRequestCycle cycle, Object o) {
>>  // Remove the row from the current TableDataModel
>>  SimpleListTableDataModel dm = ((SimpleListTableDataModel) 
>> ((SimpleTableModel)   getTableModel()).getDataModel());
>>  dm.getRows(0, dm.getRowCount()-1);
>>  dm.removeRow(o);
>>  // Remove the row from the temporary map
>>  _objectLinkMap.remove(o.toString());
>> }
>>
>> Calling removeRow() with the object o however gives me the following:
>> java.lang.UnsupportedOperationException
>> Stack Trace:
>>
>>     * java.util.AbstractList.remove(AbstractList.java:171)
>>     * java.util.AbstractList$Itr.remove(AbstractList.java:436)
>>     * java.util.AbstractCollection.remove(AbstractCollection.java:255)
>>     * 
>> org.apache.tapestry.contrib.table.model.simple.SimpleListTableDataModel.removeRow(SimpleListTableDataModel.java:129) 
>>
>>     * org.dcg.jwc.tables.DynamicTable.deleteRow(DynamicTable.java:310)
>>
>> I even set a breakpoint *in* the datamodel class on the entrypoint 
>> into the removeRow() method. The object to be removed was indeed 
>> present in the variable m_arrRows that obviously contains the objects. 
>> I even went into the AbstractCollection where object is 'sought out' 
>> and deleted. (or rather isn't).
>>
>> I'v got no idea what i'm doing wrong here so any suggestion would be 
>> welcome.
>>
>> tia,
>>
>> Fermin DCG
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: java.lang.UnsupportedOperationException??

Posted by Paul Ferraro <pm...@columbia.edu>.
Digging into this quickly, I think the problem is the underlying list 
created by SimpleListTableDataModel uses Arrays.asList().  
Unfortunately, java.util.List.remove(Object) is an optional operation, 
and it is not implemented by the list returned by Arrays.asList() (that 
makes sense since you cannot remove an arbitrary element of an array in 
this way).  It would seem that the constructor of 
SimpleListTableDataModel should instead create a new list from the array 
[e.g. ArrayList(Arrays.asList(arrRows))], so that the remove(...) 
operation will succeed as intended.
I'm no expert on the Table component, so I'd recommend you verify this 
with Mind Bridge.

Paul

F. Da Costa Gomez wrote:

> Hi,
>
> The following method is supposed to delete an object from a 
> SimpleListTableDataModel. Nothing fancy one would say.
> I checked the existence of o by calling getRows() in the debugger and 
> visually confirming the existence of o in the model.
>
> private void deleteRow(IRequestCycle cycle, Object o) {
>  // Remove the row from the current TableDataModel
>  SimpleListTableDataModel dm = ((SimpleListTableDataModel) 
> ((SimpleTableModel)   getTableModel()).getDataModel());
>  dm.getRows(0, dm.getRowCount()-1);
>  dm.removeRow(o);
>  // Remove the row from the temporary map
>  _objectLinkMap.remove(o.toString());
> }
>
> Calling removeRow() with the object o however gives me the following:
> java.lang.UnsupportedOperationException
> Stack Trace:
>
>     * java.util.AbstractList.remove(AbstractList.java:171)
>     * java.util.AbstractList$Itr.remove(AbstractList.java:436)
>     * java.util.AbstractCollection.remove(AbstractCollection.java:255)
>     * 
> org.apache.tapestry.contrib.table.model.simple.SimpleListTableDataModel.removeRow(SimpleListTableDataModel.java:129) 
>
>     * org.dcg.jwc.tables.DynamicTable.deleteRow(DynamicTable.java:310)
>
> I even set a breakpoint *in* the datamodel class on the entrypoint 
> into the removeRow() method. The object to be removed was indeed 
> present in the variable m_arrRows that obviously contains the objects. 
> I even went into the AbstractCollection where object is 'sought out' 
> and deleted. (or rather isn't).
>
> I'v got no idea what i'm doing wrong here so any suggestion would be 
> welcome.
>
> tia,
>
> Fermin DCG
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org