On 27 Nov 2003, at 16:29, Bruno Dumon wrote:
On Thu, 2003-11-27 at 13:37, Jeremy Quinn wrote:On 26 Nov 2003, at 18:19, Bruno Dumon wrote:
How do I call delete on my bean?
I am using Hibernate, it is not enough to just remove the item from
the Collection, I also need to call session.delete (resource) (or more
accurately ResourcePeer.delete (session, resource), so it is wrapped
in
a Transaction) on the deletee.
Simply execute this code from an event-handler attached to the button?
Now I am having a problem identifying which row is being deleted.
in my Model :
<wd:repeater id="resources"> <wd:widgets> <wd:output id="id"> <wd:datatype base="long"/> </wd:output> . . . <wd:row-action id="delete" action-command="delete"> <wd:label><i18n:text i18n:catalogue="local">label.delete.resource</i18n:text></wd:label> <wd:hint><i18n:text i18n:catalogue="local">hint.delete.resource</i18n:text></wd:hint> <wd:on-activate> <javascript>deleteRow (event)</javascript> </wd:on-activate> </wd:row-action> </wd:widgets> </wd:repeater>
in my Binding :
<wb:repeater id="resources" parent-path="." row-path="resources" unique-row-id="id" unique-path="id">
<wb:on-bind> <wb:value id="id" path="id"/> . . . </wb:on-bind>
<wb:on-insert-row> <wb:insert-bean classname="uk.co.my.bean.Resource" addmethod="addResource"/> </wb:on-insert-row>
<wb:on-delete-row> <wb:delete-node/> </wb:on-delete-row>
</wb:repeater>
in my FløwScript :
// event handler called by Woody to remove a Resource Row from the Album
function deleteRow (event) {
// get the ID of the Resource that is being deleted, so I can remove
it from the Persistor
cocoon.log.info ("User deleting Row :" + event.getSourceWidget
().getParent ().getId ());
I don't think this will return the id you expect. The id returned by getId() is the id of the widget as defined in the form definition, not to be confused with the unique-row-id from the binding, which just points to a widget who's value is used as unique row identification.
OK
}
this shows '-1' ( !!!! ) Has it been deleted before this handler is called?
If I go :event.getSourceWidget ().getId () I get 'delete'.
If I go :event.getSourceWidget ().getParent ().getId () I get '-1'.
If I go :event.getSourceWidget ().getParent ().getParent ().getId () I get 'resources'.
Saw your messages on the dev list (which are still valid), but you could
do this as follows:
event.getSourceWidget().getParent().getWidget("my-id- widget").getValue()
where "my-id-widget" is the widget containing your id (assuming that's what you want).
Thanks, yes that works.
the getParent() call gives you the current row in the repeater (which is
in fact also a widget, though it's not visible in the form definition,
it's automatically created for you), of which you request another child
widget using the getWidget() call.
Is it possible to get the index of the row?
It would save my Application scanning the Bean's List looking for that ID.
event.getSourceWidget ().getParent ().getParent ().indexOf (event.getSourceWidget ().getParent ())
still returns -1.
Is that because it really has been removed, or because I am asking the wrong question again ;)
Many thanks
regards Jeremy
smime.p7s
Description: S/MIME cryptographic signature