-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I have a tree and some listboxes and text boxes.
When a user selects another item in the tree or changes a listbox selection I need to check if there are un-saved changes in the text boxes and ask the user if he wants to leave without saving.
This is no problem with MessageBox etc.
But if the user does NOT want to leave without saving how can I abort/cancel the new selection in the tree or the listbox so that the old values are still selected?
My idea was to cancel the SelectEvent but I couldn't see how to do this...
Any ideas?
Hmmmmm,
i read this line 10-times. I don't understand it. Can you explain in other words.
|But if the user does NOT want to leave without saving how can I abort/cancel the new selection in the tree or the listbox so that the old values are still selected?|
Stephan
PS: I don't know but here are a few snippets:
You can store the initial values in vars and make a compare of it and restore if needed.
/** * Stores the old values */ private void doStoreInitValues() { oldVar_kunNr = kunNr.getValue(); oldVar_kunMatchcode = kunMatchcode.getValue(); oldVar_kunName1 = kunName1.getValue(); oldVar_kunName2 = kunName2.getValue(); oldVar_kunOrt = kunOrt.getValue(); oldVar_kunBranche = kunBranche.getSelectedItem(); oldVar_kunMahnsperre = kunMahnsperre.isChecked(); }
/** * Checks, if data are changed since the last call of <br> * doStoreInitData() . <br> * * @return true, if data are changed, otherwise false */ private boolean isDataChanged() { boolean changed = false; if (oldVar_kunNr != kunNr.getValue()) { changed = true; } if (oldVar_kunMatchcode != kunMatchcode.getValue()) { changed = true; } if (oldVar_kunName1 != kunName1.getValue()) { changed = true; } if (oldVar_kunName2 != kunName2.getValue()) { changed = true; } if (oldVar_kunOrt != kunOrt.getValue()) { changed = true; } if (oldVar_kunBranche != kunBranche.getSelectedItem()) { changed = true; } if (oldVar_kunMahnsperre != kunMahnsperre.isChecked()) { changed = true; } return changed; }
Hi Stephan
Thank you for your answer and sorry for my late answer. I've been on holidays.
OK. That is exactly what I want to do.
But I thought it would be possible to cancel the change (selection in the tree etc) instead of restoring to the old values.
I can try to explain it more detailled:
I have a page with a tree on the left. the user selects a product in the tree.
on the right properties are displayed for this product. Now he changes some of the product properties.
Without saving he now selects another product in the tree.
Here I want to ask the user if he really wants to leave or go back and save.
I he decides to go back for further changes and/or save I do not reload the product properties BUT in the tree on the left the new product is already selected!
Do you know if there is any other possibility instead of saving the old status and restoring it?
Something like cancel the onSelect event?
Ralf
Hi SergeTk
thank you for the idea. I will check this.
But I have the same problem with other components on the page:
- user can select another product in the tree
- user can select another currency, reporttype etc in some listboxes
and in all cases I need to check if there were unsaved changes and abort the "navigation" (selection in tree, selection in listboxes).
So, do I have to override onSelect methods of tree and listboxes?!
Ralf
Ok you right there is no onSelect (I assumed it had since it fires select event) .....
After looking at source code it seems that Listitem is the one who calls the listbox to process selection of the item
so you probably need to look at extending Listitem and overriding setSelected() method.
But once you overriden listitem there is another problem how to make sure listbox uses your listitem and not default so you would need to extend listbox as well , and override parts where it creates listitems inside render inner class ........
Asked: 2009-05-15 18:25:36 +0800
Seen: 247 times
Last updated: Jun 10 '09