Thank you Maurice, what you suggested matched the way I was trying to solve the problem, but I had to add a bit of client-side logic to decide whether to display the confirm dialog or not, basing the decision on the enabled/disabled status of the save button inside the first tab, which already implemented the logic to detect unsaved changes.
I paste the relevant bits to share my solution with you all. Probably it's not optimal at all, so please do feel free to comment/correct/laugh. :) @Override protected IAjaxCallDecorator getAjaxCallDecorator() { // Add custom decorator for tabs other than the one containing detailsPanel if ( index != 0 ) { return new AjaxCallDecorator() { @Override public CharSequence decorateScript( CharSequence script ) { // Ask for user confirmation, as tab-switching discards unsaved changes. final String saveButton = detailsPanel != null ? detailsPanel.getSaveButtonMarkupId() : ""; final StringBuffer decoration = new StringBuffer(); return decoration.append(String.format("if( document.getElementById('%s')!= null ", saveButton)) .append(String.format("&& !document.getElementById('%s').disabled ", saveButton)) .append("&& !confirm('Please note that unsaved changes will be lost.\\n\\nDo you want to switch tab?')) ") .append("{ return false; }") .append(script); } }; } return super.getAjaxCallDecorator(); } Cheers, Fabio Fioretti - WindoM On Sun, Jul 13, 2008 at 9:43 PM, Maurice Marrink <[EMAIL PROTECTED]> wrote: > Override newLink to return an ajaxfallbacklink where you have > overridden the getAjaxCallDecorator method to return a custom > IAjaxCallDecorator. > Use that to insert a javascript confirm dialog. > > Maurice > > On Fri, Jul 11, 2008 at 7:28 PM, Fabio Fioretti > <[EMAIL PROTECTED]> wrote: >> Hi all, >> >> thanks in advance for your precious support. >> >> I have an AjaxTabbedPanel with two tabs. In the first tab there is a >> panel with a form, some input fields and a save button; the content of >> the second tab is irrelevant. >> >> Use-case: >> >> 1 - user selects first tab; >> 2 - user makes some changes in the input fields but doesn't click the >> save button; >> 3 - user selects second tab. >> >> On step 3, users loses all his updates without being warned. >> >> I would like to add a javascript confirm dialog to be triggered only >> when some changes have been performed but not saved (no ModalWindow, >> just javascript). I mean something like: "There are some unsaved >> changes that will be lost, do you really want to switch tab?" <OK> >> <Cancel>. OK brings the user to the second tab, Cancel makes him stay >> in the first tab. >> >> The panel inside the first tab has a handy boolean hasUnsavedChanges() >> method, but I don't know where I could call it and how to inject an >> "if (!confirm('...')) return false;". >> >> Maybe in the onClick(AjaxRequestTarget target) method of the >> AjaxFallbackLink returned by AjaxTabbedPanel's newLink() method? >> >> What's the best way to do it? >> >> >> Thank you very much, >> >> Fabio Fioretti - WindoM >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]