You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2021/04/08 12:58:18 UTC
[myfaces-tobago] 01/03: feat: better exception handling
This is an automated email from the ASF dual-hosted git repository.
lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
commit e0121c439d973f85fe8a8930a2813f4337d8ceeb
Author: Udo Schnurpfeil <ud...@irian.eu>
AuthorDate: Thu Apr 8 12:27:31 2021 +0200
feat: better exception handling
move AJAX handling to the global exception handler
fixing/workaround some problems on client site when replace the whole DOM
issue: TOBAGO-1946
---
tobago-core/src/main/faces-config/faces-config.xml | 1 -
.../tobago/context/TobagoExceptionHandler.java | 196 ++++++++++++++-------
.../tobago/webapp/AjaxExceptionHandler.java | 123 -------------
.../tobago/webapp/AjaxExceptionHandlerFactory.java | 35 ----
.../tobago-theme-standard/src/main/js/tobago.js | 25 ++-
.../src/main/js/tobago.js.map | 2 +-
.../src/main/js/tobago.min.js | 4 +-
.../src/main/js/tobago.min.js.map | 2 +-
.../tobago-theme-standard/src/main/ts/tobago-in.ts | 4 +
.../src/main/ts/tobago-page.ts | 7 +-
.../src/main/ts/tobago-utils.ts | 3 +
11 files changed, 167 insertions(+), 235 deletions(-)
diff --git a/tobago-core/src/main/faces-config/faces-config.xml b/tobago-core/src/main/faces-config/faces-config.xml
index eacf191..9e224fd 100644
--- a/tobago-core/src/main/faces-config/faces-config.xml
+++ b/tobago-core/src/main/faces-config/faces-config.xml
@@ -66,7 +66,6 @@
</render-kit>
<factory>
- <exception-handler-factory>org.apache.myfaces.tobago.webapp.AjaxExceptionHandlerFactory</exception-handler-factory>
<exception-handler-factory>org.apache.myfaces.tobago.context.TobagoExceptionHandlerFactory</exception-handler-factory>
</factory>
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoExceptionHandler.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoExceptionHandler.java
index f2f6040..3d121d6 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoExceptionHandler.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/context/TobagoExceptionHandler.java
@@ -19,6 +19,7 @@
package org.apache.myfaces.tobago.context;
+import org.apache.myfaces.tobago.util.WebXmlUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -31,13 +32,16 @@ import javax.faces.component.UIViewRoot;
import javax.faces.context.ExceptionHandler;
import javax.faces.context.ExceptionHandlerWrapper;
import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
import javax.faces.event.ExceptionQueuedEvent;
import javax.faces.event.ExceptionQueuedEventContext;
import javax.faces.event.PhaseId;
import javax.faces.event.PreRenderViewEvent;
import javax.faces.view.ViewDeclarationLanguage;
+import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.Iterator;
@@ -45,86 +49,142 @@ public class TobagoExceptionHandler extends ExceptionHandlerWrapper {
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- private ExceptionHandler wrapped;
-
- public TobagoExceptionHandler(final ExceptionHandler wrapped) {
- this.wrapped = wrapped;
- }
-
- @Override
- public ExceptionHandler getWrapped() {
- return wrapped;
+ public TobagoExceptionHandler(final ExceptionHandler delegate) {
+ super(delegate);
}
@Override
public void handle() throws FacesException {
- final Iterator<ExceptionQueuedEvent> iterator = getUnhandledExceptionQueuedEvents().iterator();
- while (iterator.hasNext()) {
- final ExceptionQueuedEvent event = iterator.next();
- final ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
- final Throwable cause = this.getWrapped().getRootCause(context.getException());
- final FacesContext facesContext = FacesContext.getCurrentInstance();
- final NavigationHandler nav = facesContext.getApplication().getNavigationHandler();
-
- if (cause instanceof ViewExpiredException
- || cause != null && cause.getCause() instanceof ViewExpiredException) {
- final ViewExpiredException viewExpiredException = (ViewExpiredException)
- (cause instanceof ViewExpiredException ? cause : cause.getCause());
- try {
- facesContext.addMessage(null,
- new FacesMessage(FacesMessage.SEVERITY_WARN,
- "The view has been expired!",
- "Please check the given data or try to start from the beginning."));
- nav.handleNavigation(facesContext, null, viewExpiredException.getViewId());
- facesContext.renderResponse();
- LOG.debug("Handling ViewExpiredException on viewId: {}", viewExpiredException.getViewId());
- } finally {
- iterator.remove();
- }
- } else {
- try {
- final boolean error404 = cause instanceof FileNotFoundException
- || cause != null && cause.getCause() instanceof FileNotFoundException;
- final FacesMessage message;
- if (error404) {
- message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
- "The page was not found!",
- "The requested page was not found!");
- facesContext.getExternalContext().setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
- LOG.warn("Handling 404 exception.");
+ final FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ if (facesContext.getPartialViewContext().isAjaxRequest()) {
+ final Iterator<ExceptionQueuedEvent> events = getUnhandledExceptionQueuedEvents().iterator();
+ if (events.hasNext()) {
+ final Throwable exception = events.next().getContext().getException();
+ if (!(exception instanceof AbortProcessingException)) {
+ final String errorPageLocation = WebXmlUtils.getErrorPageLocation(exception);
+
+ if (errorPageLocation != null
+ && (facesContext.getCurrentPhaseId() != PhaseId.RENDER_RESPONSE
+ || !facesContext.getExternalContext().isResponseCommitted())) {
+
+ try {
+ final HttpServletRequest request = (HttpServletRequest) facesContext.getExternalContext().getRequest();
+ final HttpServletResponse response =
+ (HttpServletResponse) facesContext.getExternalContext().getResponse();
+
+ request.setAttribute("javax.servlet.error.exception", exception);
+ request.setAttribute("javax.servlet.error.exception_type", exception.getClass());
+ request.setAttribute("javax.servlet.error.message", exception.getMessage());
+ request.setAttribute("javax.servlet.error.request_uri", request.getRequestURI());
+ request.setAttribute("javax.servlet.error.status_code", HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+
+ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+
+ renderErrorPage(facesContext, errorPageLocation);
+ cleanupExceptionQueuedEvents();
+ } catch (final IOException e) {
+ throw new FacesException(e);
+ }
} else {
- message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
- "An unknown error has occurred!",
- "An unknown error has occurred!");
- facesContext.getExternalContext().setResponseStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- LOG.warn("Handling 500 exception.", cause);
+ LOG.debug("Can't return an error page. errorPageLocation='{}'", errorPageLocation);
}
- facesContext.addMessage(null, message);
- final String viewId = "/tobago/error.xhtml";
+ }
+ }
+ } else {
+ final Iterator<ExceptionQueuedEvent> iterator = getUnhandledExceptionQueuedEvents().iterator();
+ while (iterator.hasNext()) {
+ final ExceptionQueuedEvent event = iterator.next();
+ final ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
+ final Throwable cause = this.getWrapped().getRootCause(context.getException());
+ final NavigationHandler nav = facesContext.getApplication().getNavigationHandler();
- // when the rendering was not yet started, we can forward to an error page
- if (event.getContext().getPhaseId().getOrdinal() < PhaseId.RENDER_RESPONSE.getOrdinal()) {
- nav.handleNavigation(facesContext, null, viewId);
+ if (cause instanceof ViewExpiredException
+ || cause != null && cause.getCause() instanceof ViewExpiredException) {
+ final ViewExpiredException viewExpiredException = (ViewExpiredException)
+ (cause instanceof ViewExpiredException ? cause : cause.getCause());
+ try {
+ facesContext.addMessage(null,
+ new FacesMessage(FacesMessage.SEVERITY_WARN,
+ "The view has been expired!",
+ "Please check the given data or try to start from the beginning."));
+ nav.handleNavigation(facesContext, null, viewExpiredException.getViewId());
facesContext.renderResponse();
- } else {
- final HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
- response.resetBuffer(); // undo rendering, if you can.
- final ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
- final ViewDeclarationLanguage vdl = viewHandler.getViewDeclarationLanguage(facesContext, viewId);
- final UIViewRoot viewRoot = viewHandler.createView(facesContext, viewId);
- vdl.buildView(facesContext, viewRoot);
- facesContext.getApplication().publishEvent(facesContext, PreRenderViewEvent.class, viewRoot);
- vdl.renderView(facesContext, viewRoot);
- facesContext.responseComplete();
+ LOG.debug("Handling ViewExpiredException on viewId: {}", viewExpiredException.getViewId());
+ } finally {
+ iterator.remove();
+ }
+ } else {
+ try {
+ final boolean error404 = cause instanceof FileNotFoundException
+ || cause != null && cause.getCause() instanceof FileNotFoundException;
+ final FacesMessage message;
+ if (error404) {
+ message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ "The page was not found!",
+ "The requested page was not found!");
+ facesContext.getExternalContext().setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
+ LOG.warn("Handling 404 exception.");
+ } else {
+ message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ "An unknown error has occurred!" + " xxx",
+ "An unknown error has occurred!" + " xxx");
+ facesContext.getExternalContext().setResponseStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ LOG.warn("Handling 500 exception.", cause);
+ }
+ facesContext.addMessage(null, message);
+ final String viewId = "/tobago/error.xhtml";
+
+ // when the rendering was not yet started, we can forward to an error page
+ if (event.getContext().getPhaseId().getOrdinal() < PhaseId.RENDER_RESPONSE.getOrdinal()) {
+ nav.handleNavigation(facesContext, null, viewId);
+ facesContext.renderResponse();
+ } else {
+ final HttpServletResponse response =
+ (HttpServletResponse) facesContext.getExternalContext().getResponse();
+ response.resetBuffer(); // undo rendering, if you can.
+ final ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
+ final ViewDeclarationLanguage vdl = viewHandler.getViewDeclarationLanguage(facesContext, viewId);
+ final UIViewRoot viewRoot = viewHandler.createView(facesContext, viewId);
+ vdl.buildView(facesContext, viewRoot);
+ facesContext.getApplication().publishEvent(facesContext, PreRenderViewEvent.class, viewRoot);
+ vdl.renderView(facesContext, viewRoot);
+ facesContext.responseComplete();
+ }
+ } catch (Exception e) {
+ LOG.error("Exception while exception handling!", e);
+ } finally {
+ iterator.remove();
}
- } catch (Exception e) {
- LOG.error("Exception while exception handling!", e);
- } finally {
- iterator.remove();
}
}
}
- getWrapped().handle();
+
+ super.handle();
+ }
+
+ private void renderErrorPage(final FacesContext facesContext, final String errorPageLocation) throws IOException {
+ final ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
+ final UIViewRoot viewRoot = viewHandler.createView(facesContext, errorPageLocation);
+ facesContext.setViewRoot(viewRoot);
+ facesContext.getPartialViewContext().setRenderAll(true);
+
+ final ViewDeclarationLanguage viewDeclarationLanguage = viewHandler
+ .getViewDeclarationLanguage(facesContext, errorPageLocation);
+ viewDeclarationLanguage.buildView(facesContext, viewRoot);
+ facesContext.getApplication().publishEvent(facesContext, PreRenderViewEvent.class, viewRoot);
+ viewDeclarationLanguage.renderView(facesContext, viewRoot);
+
+ facesContext.responseComplete();
+ }
+
+ private void cleanupExceptionQueuedEvents() {
+ final Iterator<ExceptionQueuedEvent> exceptionQueuedEvents = getUnhandledExceptionQueuedEvents().iterator();
+ while (exceptionQueuedEvents.hasNext()) {
+ exceptionQueuedEvents.next();
+ exceptionQueuedEvents.remove();
+ }
}
+
}
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/AjaxExceptionHandler.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/AjaxExceptionHandler.java
deleted file mode 100644
index bf6f2fb..0000000
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/AjaxExceptionHandler.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.myfaces.tobago.webapp;
-
-import org.apache.myfaces.tobago.util.WebXmlUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.faces.FacesException;
-import javax.faces.application.ViewHandler;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.ExceptionHandler;
-import javax.faces.context.ExceptionHandlerWrapper;
-import javax.faces.context.FacesContext;
-import javax.faces.event.AbortProcessingException;
-import javax.faces.event.ExceptionQueuedEvent;
-import javax.faces.event.PhaseId;
-import javax.faces.event.PreRenderViewEvent;
-import javax.faces.view.ViewDeclarationLanguage;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.lang.invoke.MethodHandles;
-import java.util.Iterator;
-
-public class AjaxExceptionHandler extends ExceptionHandlerWrapper {
-
- private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
- private ExceptionHandler wrapped;
-
- AjaxExceptionHandler(final ExceptionHandler exception) {
- this.wrapped = exception;
- }
-
- @Override
- public ExceptionHandler getWrapped() {
- return wrapped;
- }
-
- @Override
- public void handle() throws FacesException {
- final FacesContext facesContext = FacesContext.getCurrentInstance();
-
- if (facesContext != null
- && facesContext.getPartialViewContext().isAjaxRequest()
- && getUnhandledExceptionQueuedEvents().iterator().hasNext()) {
-
- final Throwable exception = getUnhandledExceptionQueuedEvents().iterator().next().getContext().getException();
-
- if (!(exception instanceof AbortProcessingException)) {
- final String errorPageLocation = WebXmlUtils.getErrorPageLocation(exception);
-
- if (errorPageLocation != null
- && (facesContext.getCurrentPhaseId() != PhaseId.RENDER_RESPONSE
- || !facesContext.getExternalContext().isResponseCommitted())) {
-
- try {
- final HttpServletRequest request = (HttpServletRequest) facesContext.getExternalContext().getRequest();
- final HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
-
- request.setAttribute("javax.servlet.error.exception", exception);
- request.setAttribute("javax.servlet.error.exception_type", exception.getClass());
- request.setAttribute("javax.servlet.error.message", exception.getMessage());
- request.setAttribute("javax.servlet.error.request_uri", request.getRequestURI());
- request.setAttribute("javax.servlet.error.status_code", HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-
- response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-
- renderErrorPage(facesContext, errorPageLocation);
- cleanupExceptionQueuedEvents();
- } catch (final IOException e) {
- throw new FacesException(e);
- }
- } else {
- LOG.debug("Can't return an error page. errorPageLocation='{}'", errorPageLocation);
- }
- }
- }
-
- getWrapped().handle();
- }
-
- private void renderErrorPage(final FacesContext facesContext, final String errorPageLocation) throws IOException {
- final ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
- final UIViewRoot viewRoot = viewHandler.createView(facesContext, errorPageLocation);
- facesContext.setViewRoot(viewRoot);
- facesContext.getPartialViewContext().setRenderAll(true);
-
- final ViewDeclarationLanguage viewDeclarationLanguage = viewHandler
- .getViewDeclarationLanguage(facesContext, errorPageLocation);
- viewDeclarationLanguage.buildView(facesContext, viewRoot);
- facesContext.getApplication().publishEvent(facesContext, PreRenderViewEvent.class, viewRoot);
- viewDeclarationLanguage.renderView(facesContext, viewRoot);
-
- facesContext.responseComplete();
- }
-
- private void cleanupExceptionQueuedEvents() {
- final Iterator<ExceptionQueuedEvent> exceptionQueuedEvents = getUnhandledExceptionQueuedEvents().iterator();
- while (exceptionQueuedEvents.hasNext()) {
- exceptionQueuedEvents.next();
- exceptionQueuedEvents.remove();
- }
- }
-}
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/AjaxExceptionHandlerFactory.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/AjaxExceptionHandlerFactory.java
deleted file mode 100644
index 27c50b7..0000000
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/AjaxExceptionHandlerFactory.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.myfaces.tobago.webapp;
-
-import javax.faces.context.ExceptionHandler;
-import javax.faces.context.ExceptionHandlerFactory;
-
-public class AjaxExceptionHandlerFactory extends ExceptionHandlerFactory {
-
- public AjaxExceptionHandlerFactory(final ExceptionHandlerFactory parent) {
- super(parent);
- }
-
- @Override
- public ExceptionHandler getExceptionHandler() {
- return new AjaxExceptionHandler(getWrapped().getExceptionHandler());
- }
-}
diff --git a/tobago-theme/tobago-theme-standard/src/main/js/tobago.js b/tobago-theme/tobago-theme-standard/src/main/js/tobago.js
index e393ace..c914e92 100644
--- a/tobago-theme/tobago-theme-standard/src/main/js/tobago.js
+++ b/tobago-theme/tobago-theme-standard/src/main/js/tobago.js
@@ -161,6 +161,9 @@
// todo: may return NodeListOf<HTMLElementTagNameMap[K]> or something like that.
static selfOrQuerySelectorAll(element, selectors) {
const result = new Array();
+ if (!element) {
+ element = document.documentElement;
+ }
if (element.matches(selectors)) {
result.push(element);
}
@@ -3261,6 +3264,17 @@
function getContainingBlock(element) {
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') !== -1;
+ var isIE = navigator.userAgent.indexOf('Trident') !== -1;
+
+ if (isIE && isHTMLElement(element)) {
+ // In IE 9, 10 and 11 fixed elements containing block is always established by the viewport
+ var elementCss = getComputedStyle$1(element);
+
+ if (elementCss.position === 'fixed') {
+ return null;
+ }
+ }
+
var currentNode = getParentNode(element);
while (isHTMLElement(currentNode) && ['html', 'body'].indexOf(getNodeName(currentNode)) < 0) {
@@ -10271,10 +10285,14 @@
ReloadManager.instance.schedule(id, JSON.parse(result[1]).reload.frequency);
}
else {
+ let rootNode = this.getRootNode();
+ // XXX in case of "this" is tobago-page (e.g. ajax exception handling) rootNode is not set correctly???
+ if (!rootNode.getElementById) {
+ rootNode = document;
+ }
console.info("[tobago-jsf] Update after jsf.ajax success: %s", id);
if (JsfParameter.isJsfId(id)) {
console.debug("[tobago-jsf] updating #%s", id);
- const rootNode = this.getRootNode();
const element = rootNode.getElementById(id);
if (element) {
Listener.executeAfterUpdate(element);
@@ -10286,7 +10304,6 @@
else if (JsfParameter.isJsfBody(id)) {
console.debug("[tobago-jsf] updating body");
// there should be only one element with this tag name
- const rootNode = this.getRootNode();
Listener.executeAfterUpdate(rootNode.querySelector("tobago-page"));
}
}
@@ -11453,6 +11470,7 @@
console.debug("constructor: '%s'", element.id);
this.element.addEventListener("change", this.checkValue.bind(this));
}
+ // todo: use "custom-elements" instead of this init listener
static init(element) {
for (const input of RegExpTest.selfOrElementsByClassName(element, "tobago-in")) { // todo only for data-regexp
new RegExpTest(input);
@@ -11465,6 +11483,9 @@
*/
static selfOrElementsByClassName(element, className) {
const result = new Array();
+ if (!element) {
+ element = document.documentElement;
+ }
if (element.classList.contains(className)) {
result.push(element);
}
diff --git a/tobago-theme/tobago-theme-standard/src/main/js/tobago.js.map b/tobago-theme/tobago-theme-standard/src/main/js/tobago.js.map
index af2bdfa..03aebdd 100644
--- a/tobago-theme/tobago-theme-standard/src/main/js/tobago.js.map
+++ b/tobago-theme/tobago-theme-standard/src/main/js/tobago.js.map
@@ -1 +1 @@
-{"version":3,"file":"tobago.js","sources":["../ts/tobago-listener.ts","../ts/tobago-utils.ts","../ts/tobago-bar.ts","../ts/tobago-dropdown.ts","../../../../node_modules/vanillajs-datepicker/js/lib/utils.js","../../../../node_modules/vanillajs-datepicker/js/lib/date.js","../../../../node_modules/vanillajs-datepicker/js/lib/date-format.js","../../../../node_modules/vanillajs-datepicker/js/lib/event.js","../../../../node_modules/vanillajs-datepicker/js/i18n/base-locales.js","../../../../nod [...]
\ No newline at end of file
+{"version":3,"file":"tobago.js","sources":["../ts/tobago-listener.ts","../ts/tobago-utils.ts","../ts/tobago-bar.ts","../ts/tobago-dropdown.ts","../../../../node_modules/vanillajs-datepicker/js/lib/utils.js","../../../../node_modules/vanillajs-datepicker/js/lib/date.js","../../../../node_modules/vanillajs-datepicker/js/lib/date-format.js","../../../../node_modules/vanillajs-datepicker/js/lib/event.js","../../../../node_modules/vanillajs-datepicker/js/i18n/base-locales.js","../../../../nod [...]
\ No newline at end of file
diff --git a/tobago-theme/tobago-theme-standard/src/main/js/tobago.min.js b/tobago-theme/tobago-theme-standard/src/main/js/tobago.min.js
index cbe0c70..db3b549 100644
--- a/tobago-theme/tobago-theme-standard/src/main/js/tobago.min.js
+++ b/tobago-theme/tobago-theme-standard/src/main/js/tobago.min.js
@@ -1,8 +1,8 @@
-!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";var e,t;!function(e){e[e.DOCUMENT_READY=0]="DOCUMENT_READY",e[e.WINDOW_LOAD=1]="WINDOW_LOAD",e[e.BEFORE_SUBMIT=2]="BEFORE_SUBMIT",e[e.AFTER_UPDATE=3]="AFTER_UPDATE",e[e.BEFORE_UNLOAD=4]="BEFORE_UNLOAD",e[e.BEFORE_EXIT=5]="BEFORE_EXIT"}(e||(e={})),function(e){e[e.EARLIER=0]="EARLIER",e[e.EARLY=1]="EARLY",e[e.NORMAL=2]="NORMAL",e[e.LATE=3]="LATE",e[e.LATER=4]="LATER"}(t||(t={}));class s{constructor() [...]
+!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";var e,t;!function(e){e[e.DOCUMENT_READY=0]="DOCUMENT_READY",e[e.WINDOW_LOAD=1]="WINDOW_LOAD",e[e.BEFORE_SUBMIT=2]="BEFORE_SUBMIT",e[e.AFTER_UPDATE=3]="AFTER_UPDATE",e[e.BEFORE_UNLOAD=4]="BEFORE_UNLOAD",e[e.BEFORE_EXIT=5]="BEFORE_EXIT"}(e||(e={})),function(e){e[e.EARLIER=0]="EARLIER",e[e.EARLY=1]="EARLY",e[e.NORMAL=2]="NORMAL",e[e.LATE=3]="LATE",e[e.LATER=4]="LATER"}(t||(t={}));class s{constructor() [...]
/*!
* Bootstrap v5.0.0-beta3 (https://getbootstrap.com/)
* Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
*/
-const Es="transitionend",Ls=e=>{do{e+=Math.floor(1e6*Math.random())}while(document.getElementById(e));return e},Ss=e=>{let t=e.getAttribute("data-bs-target");if(!t||"#"===t){let s=e.getAttribute("href");if(!s||!s.includes("#")&&!s.startsWith("."))return null;s.includes("#")&&!s.startsWith("#")&&(s="#"+s.split("#")[1]),t=s&&"#"!==s?s.trim():null}return t},xs=e=>{const t=Ss(e);return t&&document.querySelector(t)?t:null},ks=e=>{const t=Ss(e);return t?document.querySelector(t):null},As=e=>{i [...]
+const Es="transitionend",Ls=e=>{do{e+=Math.floor(1e6*Math.random())}while(document.getElementById(e));return e},Ss=e=>{let t=e.getAttribute("data-bs-target");if(!t||"#"===t){let s=e.getAttribute("href");if(!s||!s.includes("#")&&!s.startsWith("."))return null;s.includes("#")&&!s.startsWith("#")&&(s="#"+s.split("#")[1]),t=s&&"#"!==s?s.trim():null}return t},xs=e=>{const t=Ss(e);return t&&document.querySelector(t)?t:null},ks=e=>{const t=Ss(e);return t?document.querySelector(t):null},As=e=>{i [...]
//# sourceMappingURL=tobago.min.js.map
diff --git a/tobago-theme/tobago-theme-standard/src/main/js/tobago.min.js.map b/tobago-theme/tobago-theme-standard/src/main/js/tobago.min.js.map
index 5041948..bcd81df 100644
--- a/tobago-theme/tobago-theme-standard/src/main/js/tobago.min.js.map
+++ b/tobago-theme/tobago-theme-standard/src/main/js/tobago.min.js.map
@@ -1 +1 @@
-{"version":3,"file":"tobago.min.js","sources":["../ts/tobago-listener.ts","../ts/tobago-utils.ts","../ts/tobago-bar.ts","../ts/tobago-dropdown.ts","../../../../node_modules/vanillajs-datepicker/js/lib/utils.js","../../../../node_modules/vanillajs-datepicker/js/lib/date.js","../../../../node_modules/vanillajs-datepicker/js/lib/date-format.js","../../../../node_modules/vanillajs-datepicker/js/lib/event.js","../../../../node_modules/vanillajs-datepicker/js/i18n/base-locales.js","../../../.. [...]
\ No newline at end of file
+{"version":3,"file":"tobago.min.js","sources":["../ts/tobago-listener.ts","../ts/tobago-utils.ts","../ts/tobago-bar.ts","../ts/tobago-dropdown.ts","../../../../node_modules/vanillajs-datepicker/js/lib/utils.js","../../../../node_modules/vanillajs-datepicker/js/lib/date.js","../../../../node_modules/vanillajs-datepicker/js/lib/date-format.js","../../../../node_modules/vanillajs-datepicker/js/lib/event.js","../../../../node_modules/vanillajs-datepicker/js/i18n/base-locales.js","../../../.. [...]
\ No newline at end of file
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-in.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-in.ts
index 2752053..27895d6 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-in.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-in.ts
@@ -50,6 +50,7 @@ class RegExpTest {
private readonly element: HTMLInputElement;
private readonly regexp: RegExp;
+ // todo: use "custom-elements" instead of this init listener
static init(element: HTMLElement): void {
for (const input of RegExpTest.selfOrElementsByClassName(element, "tobago-in")) { // todo only for data-regexp
new RegExpTest(input as HTMLInputElement);
@@ -63,6 +64,9 @@ class RegExpTest {
*/
static selfOrElementsByClassName(element: HTMLElement, className: string): Array<HTMLElement> {
const result: Array<HTMLElement> = new Array<HTMLElement>();
+ if (!element) {
+ element = document.documentElement;
+ }
if (element.classList.contains(className)) {
result.push(element);
}
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-page.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-page.ts
index 7fe77a0..ad2f41a 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-page.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-page.ts
@@ -162,10 +162,14 @@ export class Page extends HTMLElement {
console.debug("[tobago-jsf] Found reload-JSON in response!");
ReloadManager.instance.schedule(id, JSON.parse(result[1]).reload.frequency);
} else {
+ let rootNode = this.getRootNode() as ShadowRoot | Document;
+ // XXX in case of "this" is tobago-page (e.g. ajax exception handling) rootNode is not set correctly???
+ if (! rootNode.getElementById) {
+ rootNode = document;
+ }
console.info("[tobago-jsf] Update after jsf.ajax success: %s", id);
if (JsfParameter.isJsfId(id)) {
console.debug("[tobago-jsf] updating #%s", id);
- const rootNode = this.getRootNode() as ShadowRoot | Document;
const element = rootNode.getElementById(id);
if (element) {
Listener.executeAfterUpdate(element);
@@ -175,7 +179,6 @@ export class Page extends HTMLElement {
} else if (JsfParameter.isJsfBody(id)) {
console.debug("[tobago-jsf] updating body");
// there should be only one element with this tag name
- const rootNode = this.getRootNode() as ShadowRoot | Document;
Listener.executeAfterUpdate(rootNode.querySelector("tobago-page") as HTMLElement);
}
}
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-utils.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-utils.ts
index df8f09e..55c84e7 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-utils.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-utils.ts
@@ -26,6 +26,9 @@ export class DomUtils {
// todo: may return NodeListOf<HTMLElementTagNameMap[K]> or something like that.
static selfOrQuerySelectorAll(element: HTMLElement, selectors: string): Array<HTMLElement> {
const result: Array<HTMLElement> = new Array<HTMLElement>();
+ if (!element) {
+ element = document.documentElement;
+ }
if (element.matches(selectors)) {
result.push(element);
}