-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello colleagues,
I have the following problem:
I have various tabs for different groups of properties of resources that can be edited in forms on these tabs. Some of the tabs require unsaved changes to be applied or discarded before switching to certain other tabs. To implement this, I assigned the tabs to groups. Whenever the tab group changes, I open a dialog and ask the user to apply, discard, or cancel. Everything works fine now except that the tab is switched independently of my dialog.
So what I need to do is somehow intercept the the select-event sent to the tab(box) so that selectTabDirectly(...) is not called on the tab box if the user cancels switching of the tab. Does anyone know how to achieve that?
Thanks beforehand,
David
the Sample Code:Leave tab selection solution of jimmyshiau is my savior. but how to do this programmatically? I need to save the dirty tab first before actually leaving the tab.. i wish to do this code: w:_sel="switchTab" forward="onSwitchTab=onSwitchTab" on different controller but how?
Hi sassyshin,
sorry for this late response but I was on holiday. Also, I cannot tell you much about it as it is already quite some time ago. But here is what I got:
We manage the currently focused tab in the view model (vm.focusTab) and we have included the above solution using switchTab and onSwitchTab
<tab id="mGeneralAttributes" label="${labels.tabs.GeneralAttributes}" selected="@load(vm.focusTab eq 'mGeneralAttributes')" w:_sel="switchTab" forward="onSwitchTab=onSwitchTab"/>
We also apply several composers to the window:
apply="${StructureComposer},${StructureTabForwardComposer}"
In this composer we have the onSwitchTab(ForwardEvent) method which compares the tab groups and triggers saving when the group is to be switched. We use groups so as to allow switches between tabs in one group without saving:
@Command public void onSwitchTab(ForwardEvent event) throws InterruptedException { ... // event delivers target tab and origin tab final Tab tab = (Tab)event.getOrigin().getTarget(); String tabNameTarget = event.getOrigin().getTarget().getId(); String tabGroupTarget = mTabGroups.get(tabNameTarget); String tabNameOrigin = layer.getFocusTab(); String tabGroupOrigin = mTabGroups.get(tabNameOrigin); ... // if save is required, ask for confirmation or cancel and save and switch if confirmed
Hope this helps,
David
Hello,
How to do the same, when tab is being created from server end, through Java code.
public void afterCompose(@ContextParam(ContextType.VIEW) Component view) { //Component tab Tabs tabs = (Tabs) view.getFellowIfAny("tabs"); for(int i=0; i<5; i++) { Tab tab = new Tab(); tab.setLabel("Tab " + i); tab.setWidgetListener("onSelect", "switch"); tab.addEventListener("onSwitchTab", new EventListener() { public void onEvent(Event event) throws Exception { final Tab tab = (Tab) event.getTarget(); String msg="Are you sure to leave " + tab.getLabel() + "?"; if (hasDirty()) { Messagebox.show(msg, "Exit", Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION, new EventListener() { public void onEvent(Event event) throws Exception { String evtName = event.getName(); if (Messagebox.ON_OK.equals(evtName)) { tab.setSelected(true); } else if (Messagebox.ON_CANCEL .equals(evtName)) { // do nothing } } }); } else { tab.setSelected(true); } } }); tab.setParent(tabs); } } public boolean hasDirty(){ return true; }
My requirement is to check hasDirty for current tab. The tab should not be switched if some data is changed in form.
Thanks,
Santosh
Asked: 2011-12-09 11:46:10 +0800
Seen: 750 times
Last updated: Jan 21 '13