You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Martin DeMello <ma...@yahoo.com> on 2003/12/24 08:42:25 UTC

Re: getting back an object from a datamodel: SOLVED!

Finally solved it. 

1. I changed currentRow from a property of the TableList to a parameter, and
made it a property of the page instead, java type defined as Object in the
TableList but as the specific hibernate datatype in the page. 

2. Then I changed deleteObject in the base AppPage to call an abstract String
deleteQuery, which I defined in the calling page as "from ClassName where
id='"+currentRow.getPK()+"'", getPK being the table-specific primary key I
inherited from the database. 

Thanks for all the help, everyone!

martin

--- Martin DeMello <ma...@yahoo.com> wrote:
> I have a List I get from a Hibernate query, which I use to initialise an
> ITableDataModel. Now I want a 'delete' link on every row of the table, which
> I
> try to implement thus (mostly copied from the LocaleTable component):
> 
> In the TableList component:
> 
>         <component id="deleteRow" type="DirectLink">
> 		<binding name="listener" expression="listeners.deleteRow"/>
> 		<binding name="parameters" expression="deleteRowContext"/>
> 	</component>
> 
> 	public Object getDeleteRowContext()
> 	{
> 		return getCurrentRow(); 
> 	}
> 
>         public void deleteRow(IRequestCycle cycle) { 
> 		Object row = cycle.getServiceParameters()[0];
> 		((SimpleListTableDataModel) getDataModel()).removeRow(row);
> 		((AppPage) getPage()).deleteObject(row);
> 		cycle.activate(getPage());
> 	}
> 
> And in AppPage
> 
> 	public void deleteObject(Object obj) 
> 	{
> 		Session sess = null;
> 		try {
> 			sess = getSession();
> 			sess.lock(obj, LockMode.NONE);
> 			session.delete(obj); 
> 			sess.flush();
> 		} catch (Exception e) {
> 			throw new RuntimeException(e);
> 		} finally {
> 			if (sess != null)
> 				try {
> 					sess.close();
> 				} catch (Exception e) {
> 					e.printStackTrace();
> 				}
> 		}
> 	}
> 
> 
> Except that the row returned by getCurrentRow doesn't seem to be the
> Hibernate
> object in the List, so nothing gets deleted. Can anyone see what I'm doing
> wrong? I thought the DataModel held references to the original objects, so
> sess.lock(obj) should have retrieved the row from the database and deleted
> it.
> 
> martin
>         
> 
>         
> 
> 
> 
> __________________________________
> Do you Yahoo!?
> New Yahoo! Photos - easier uploading and sharing.
> http://photos.yahoo.com/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/

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