11/*
2- * Copyright (C) 2004-2008 Jive Software, 2017-2025 Ignite Realtime Foundation. All rights reserved.
2+ * Copyright (C) 2004-2008 Jive Software, 2017-2026 Ignite Realtime Foundation. All rights reserved.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -368,15 +368,6 @@ private static synchronized void rebuildModel() {
368368 Element existingTab = getElemnetByID (id );
369369 // Simple case, there is no existing tab with the same id.
370370 if (existingTab == null ) {
371- // Make sure that the URL on the tab is set. If not, default to the
372- // url of the first item.
373- if (tab .attributeValue ("url" ) == null ) {
374- Element firstItem = (Element ) tab .selectSingleNode (
375- "//item[@url]" );
376- if (firstItem != null ) {
377- tab .addAttribute ("url" , firstItem .attributeValue ("url" ));
378- }
379- }
380371 generatedModel .add (tab .createCopy ());
381372 }
382373 // More complex case -- a tab with the same id already exists.
@@ -390,6 +381,23 @@ private static synchronized void rebuildModel() {
390381
391382 // OF-1484: Order everything explicitly.
392383 orderModel ();
384+
385+ // Only after explicit ordering is applied (OF-3168), make sure that the URL on every tab is set. If not,
386+ // default to the url of the first item.
387+ for (Object o : generatedModel .selectNodes ("//adminconsole//tab" )) {
388+ Element tab = (Element ) o ;
389+ if (tab .attributeValue ("url" ) == null ) {
390+ final List <Element > sidebars = tab .elements ("sidebar" );
391+ if (!sidebars .isEmpty ()) {
392+ sidebars .sort (new ElementByOrderAttributeComparator ());
393+ final List <Element > items = sidebars .get (0 ).elements ("item" );
394+ if (!items .isEmpty ()) {
395+ items .sort (new ElementByOrderAttributeComparator ());
396+ tab .addAttribute ("url" , items .get (0 ).attributeValue ("url" ));
397+ }
398+ }
399+ }
400+ }
393401 }
394402
395403 /**
0 commit comments