You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2026/10/08 19:17:22 UTC
(myfaces-tobago) 01/02: fix(ajax-queue): overlay must stay till queue is finished
This is an automated email from the ASF dual-hosted git repository.
henningn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
commit dae7a9a66cdba347db0ca0d1b97fa6a925fc734d
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Wed Oct 7 14:04:34 2026 +0200
fix(ajax-queue): overlay must stay till queue is finished
Refactor tobago-ajax-queue.ts, so the ajaxEventListener() could be removed and the AjaxQueueStatic.ajaxEventListener() method is called directly.
Remove the Overlay.getEnhancedRequestOptions() method. Now, if the Tobago Ajax queue is used (tobago.ajax.request()), there is automatically an overlay. The enhancement of the faces.ajax.RequestOptions happens now in the AjaxQueueStatic.request() method and is called Overlay.initAjaxQueueOverlays().
fix: overlay stays after shown as long as the corresponding render id is part of the Tobago Ajax queue.
CSS: transition property on the overlay is only active if ".fade" class is used.
If an overlay is set with a delay of "0", the .fade class is not used and the overlay shows up immediately.
Add test.
Issue: TOBAGO-2549
---
.../webapp/content/900-test/z-misc/ajax/Ajax.xhtml | 14 ++++
.../content/900-test/z-misc/ajax/Ajax.test.ts | 25 ++++++
tobago-theme/src/main/scss/_tobago.scss | 5 +-
.../src/main/ts/tobago-ajax-queue-static.ts | 2 +
.../src/main/ts/tobago-ajax-queue.ts | 10 +--
.../src/main/ts/tobago-behavior.ts | 4 +-
.../src/main/ts/tobago-overlay.ts | 89 +++++++++++++---------
.../src/main/ts/tobago-paginator.ts | 4 +-
tobago-theme/tsconfig.json | 2 +-
9 files changed, 106 insertions(+), 49 deletions(-)
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/z-misc/ajax/Ajax.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/z-misc/ajax/Ajax.xhtml
index 6e7d6e2647..7e702d8e0b 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/z-misc/ajax/Ajax.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/z-misc/ajax/Ajax.xhtml
@@ -42,4 +42,18 @@
<tc:out id="timestamp" label="Timestamp" value="#{ajaxSpecialCharacterController.timestamp}"/>
+ <tc:section label="Test overlay">
+ <p>An overlay should be shown if an Ajax request takes longer than one second. If an overlay is shown, it must stay,
+ till the corresponding render id is removed from the Tobago Ajax queue.</p>
+
+ <tc:in id="overlayTestInput" value="change text to force next ajax request into queue"/>
+ <tc:out id="overlayTestOutput" value="#{partialReloadController.currentDate}">
+ <f:convertDateTime pattern="HH:MM:ss.SSS"/>
+ </tc:out>
+
+ <tc:button id="overlayTestButton" label="Reload (wait 3 s)" action="#{partialReloadController.waitAndReload3}">
+ <f:ajax execute="overlayTestInput" render="overlayTestOutput"/>
+ </tc:button>
+ </tc:section>
+
</ui:composition>
diff --git a/tobago-example/tobago-example-demo/src/test/typescript/content/900-test/z-misc/ajax/Ajax.test.ts b/tobago-example/tobago-example-demo/src/test/typescript/content/900-test/z-misc/ajax/Ajax.test.ts
index cadec0c000..1efb00b82f 100644
--- a/tobago-example/tobago-example-demo/src/test/typescript/content/900-test/z-misc/ajax/Ajax.test.ts
+++ b/tobago-example/tobago-example-demo/src/test/typescript/content/900-test/z-misc/ajax/Ajax.test.ts
@@ -56,4 +56,29 @@ test.describe("900-test/z-misc/ajax/Ajax.xhtml", () => {
await expect(html).toHaveCount(1);
await expect(body).not.toHaveCSS("overflow", "hidden");
});
+
+ test("Tobago Ajax queue overlay", async ({page}) => {
+ const input = page.locator("[id='page:mainForm:overlayTestInput::field']");
+ const output = page.locator("[id='page:mainForm:overlayTestOutput']");
+ const text = output.locator(".form-control-plaintext");
+ const overlay = output.locator("tobago-overlay");
+ const button = page.locator("[id='page:mainForm:overlayTestButton']");
+
+ let textValue = (await text.textContent())!;
+
+ await expect(overlay).not.toBeVisible();
+ await expect(text).toHaveText(textValue);
+
+ await button.click(); //click has a delay of 3 seconds
+ await expect(text).toHaveText(textValue);
+ await expect(overlay).toContainClass("show");
+
+ await input.fill("Bob");
+ await button.click(); //add another 3 seconds to queue
+ await expect(text).toHaveText(textValue); //text value not changed means, the first Ajax request is still running
+ await expect(overlay).toContainClass("show");
+
+ await expect(text).not.toHaveText(textValue); //second Ajax request is running
+ await expect(overlay).toContainClass("show", {timeout: 500}); //timeout must be < 1 s, because after that the new overlay is shown
+ });
});
diff --git a/tobago-theme/src/main/scss/_tobago.scss b/tobago-theme/src/main/scss/_tobago.scss
index 0273156859..735726c826 100644
--- a/tobago-theme/src/main/scss/_tobago.scss
+++ b/tobago-theme/src/main/scss/_tobago.scss
@@ -1155,10 +1155,13 @@ tobago-overlay {
display: flex;
align-items: center;
justify-content: center;
- transition: background-color .15s linear; //similar to .fade from Bootstrap
overflow: hidden;
z-index: 5; //set to "5", because this is the highest fixed value in Bootstrap
+ &.fade {
+ transition: background-color .15s linear; //similar to .fade from Bootstrap
+ }
+
&.show {
background-color: rgba(var(--#{$prefix}body-bg-rgb), 90%);
}
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-ajax-queue-static.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-ajax-queue-static.ts
index 5592d73d32..16aa6599b7 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-ajax-queue-static.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-ajax-queue-static.ts
@@ -18,6 +18,7 @@
*/
import {QueueItem} from "./tobago-ajax-queue";
+import {Overlay} from "./tobago-overlay";
/**
* Static logic for AjaxQueue class for better testing.
@@ -44,6 +45,7 @@ export class AjaxQueueStatic {
func: facesAjaxRequest,
inProgress: false
});
+ Overlay.initAjaxQueueOverlays(queue, options);
this.processQueue(queue);
}
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-ajax-queue.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-ajax-queue.ts
index b637849e62..6be14530fc 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-ajax-queue.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-ajax-queue.ts
@@ -48,14 +48,14 @@ class AjaxQueue {
if (currentOnEvent) {
currentOnEvent(data);
}
- this.ajaxEventListener(data.source, data.type, data.status);
+ AjaxQueueStatic.ajaxEventListener(this.queue, data.source, data.type, data.status);
};
const currentOnError = options.onerror;
options.onerror = (data: faces.AjaxError) => {
if (currentOnError) {
currentOnError(data);
}
- this.ajaxEventListener(data.source, data.type, data.status);
+ AjaxQueueStatic.ajaxEventListener(this.queue, data.source, data.type, data.status);
};
AjaxQueueStatic.request(this.queue, element, event, options, () => faces.ajax.request(element, event, options));
@@ -70,12 +70,6 @@ class AjaxQueue {
faces.ajax.request(element, event, options);
}
}
-
- private ajaxEventListener(source: Element,
- type: "event" | "error",
- status: faces.AjaxEventStatus | faces.AjaxErrorStatus | "clientError" | "timeout"): void {
- AjaxQueueStatic.ajaxEventListener(this.queue, source, type, status);
- }
}
export const ajaxQueue = new AjaxQueue();
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-behavior.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-behavior.ts
index 2fff36d239..9d07303326 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-behavior.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-behavior.ts
@@ -114,7 +114,7 @@ export class Behavior extends HTMLElement {
tobago.ajax.request(
this.actionElement,
event,
- Overlay.getEnhancedRequestOptions({
+ {
params: {
"jakarta.faces.behavior.event": this.event
},
@@ -162,7 +162,7 @@ export class Behavior extends HTMLElement {
}
}
}
- }));
+ });
break;
case BehaviorMode.full:
setTimeout(this.submit.bind(this), this.delay);
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-overlay.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-overlay.ts
index 6a87816ebb..868f1901ba 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-overlay.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-overlay.ts
@@ -22,47 +22,66 @@
import {Page} from "./tobago-page";
import {OverlayType} from "./tobago-overlay-type";
import {Css} from "./tobago-css";
+import {QueueItem} from "./tobago-ajax-queue";
export class Overlay extends HTMLElement {
+ private static overlayWasShown = new Set<string>();
/**
- * Enhance or create faces.ajax.RequestOptions to use an overlay for the Ajax request.
+ * Enhance faces.ajax.RequestOptions to handle overlays for the Tobago Ajax queue.
+ *
+ * If an Ajax request is executed, a tobago-overlay component is set for all render Ids of the Tobago Ajax queue. If
+ * an overlay is shown, it keeps showing till the corresponding renderId is not in the Tobago Ajax queue anymore.
+ *
+ * @param queue Tobago Ajax queue
+ * @param options faces.ajax.RequestOptions
*/
- static getEnhancedRequestOptions(options: faces.ajax.RequestOptions = {}): faces.ajax.RequestOptions {
- const renderIds = new Set<string>();
- if (options.render) {
- for (const id of options.render.split(" ")) {
- renderIds.add(id);
- }
- }
-
- const currentOnEvent = options.onevent;
- options.onevent = (data: faces.AjaxEvent) => {
- if (currentOnEvent) {
- currentOnEvent(data);
- }
+ static initAjaxQueueOverlays(queue: QueueItem[], options: faces.ajax.RequestOptions): void {
+ if (options) {
+ const requestOptionsRenderIds = new Set<string>(options.render ? options.render.split(" ") : []);
+ const ajaxQueueRenderIds = new Set<string>(queue.flatMap(queueItem => [...queueItem.renderIds]));
+
+ const currentOnEvent = options.onevent;
+ options.onevent = (data: faces.AjaxEvent) => {
+ if (currentOnEvent) {
+ currentOnEvent(data);
+ }
- if (data.status === "begin") {
- for (const renderId of renderIds) {
- Overlay.render(renderId, OverlayType.ajax);
+ if (data.status === "begin") {
+ for (const renderId of ajaxQueueRenderIds) {
+ if (this.overlayWasShown.has(renderId)) {
+ Overlay.render(renderId, OverlayType.ajax, 0);
+ } else {
+ Overlay.render(renderId, OverlayType.ajax);
+ }
+ }
+ } else if (data.status === "complete") {
+ for (const renderId of ajaxQueueRenderIds) {
+ const overlay = document.querySelector("[id='" + renderId + "'] tobago-overlay");
+ if (overlay.classList.contains(Css.SHOW)) {
+ this.overlayWasShown.add(renderId);
+ }
+ }
+ } else if (data.status === "success") {
+ for (const renderId of requestOptionsRenderIds) {
+ Overlay.remove(renderId);
+ }
+ if (queue.length === 0) {
+ this.overlayWasShown.clear();
+ }
}
- } else if (data.status === "success") {
- for (const renderId of renderIds) {
- Overlay.remove(renderId);
+ };
+ const currentOnError = options.onerror;
+ options.onerror = (data: faces.AjaxError) => {
+ if (currentOnError) {
+ currentOnError(data);
}
- }
- };
- const currentOnError = options.onerror;
- options.onerror = (data: faces.AjaxError) => {
- if (currentOnError) {
- currentOnError(data);
- }
- for (const renderId of renderIds) {
- Overlay.render(renderId, OverlayType.error);
- }
- };
- return options;
+ for (const renderId of requestOptionsRenderIds) {
+ Overlay.render(renderId, OverlayType.error);
+ }
+ };
+ }
}
static render(id: string, type: OverlayType, delay: number = Page
@@ -74,7 +93,7 @@ export class Overlay extends HTMLElement {
if (currentOverlay === null) {
element.insertAdjacentHTML("beforeend", Overlay.htmlText(id, type,
- delay ? delay : Page.page(document.querySelector("tobago-page")).waitOverlayDelayAjax));
+ delay >= 0 ? delay : Page.page(document.querySelector("tobago-page")).waitOverlayDelayAjax));
} else if (currentOverlayType !== type) {
currentOverlay?.remove();
element.insertAdjacentHTML("beforeend", Overlay.htmlText(id, type, 0));
@@ -89,8 +108,8 @@ export class Overlay extends HTMLElement {
}
static htmlText(id: string, type: OverlayType, delay: number): string {
- return `<tobago-overlay type='${type}' for='${id}' delay='${delay}' class='fade${type === OverlayType.error
- ? " text-danger" : ""}'/>`;
+ return `<tobago-overlay type='${type}' for='${id}' delay='${delay}' class='${delay > 0
+ ? "fade" : ""}${type === OverlayType.error ? " text-danger" : ""}'/>`;
}
private timeout;
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-paginator.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-paginator.ts
index e02d93960b..79db1ea67d 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-paginator.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-paginator.ts
@@ -96,13 +96,13 @@ export class TobagoPaginator extends HTMLElement {
tobago.ajax.request(
this.id,
null,
- Overlay.getEnhancedRequestOptions({
+ {
params: {
"jakarta.faces.behavior.event": "reload"
},
execute: sheet.id,
render: sheet.id
- }));
+ });
}
get text(): HTMLElement {
diff --git a/tobago-theme/tsconfig.json b/tobago-theme/tsconfig.json
index 973b0151a1..301e219a61 100644
--- a/tobago-theme/tsconfig.json
+++ b/tobago-theme/tsconfig.json
@@ -1,6 +1,6 @@
{
"compilerOptions": {
- "target": "es2016",
+ "target": "es2019",
"strict": false,
"types": [
"jest",