From 436918e52a0c89eaa2baa0aadc71de093b6f24f5 Mon Sep 17 00:00:00 2001 From: Robotcell <105160953+Robotcell@users.noreply.github.com> Date: Wed, 25 Nov 2026 13:29:29 +0300 Subject: [PATCH 1/2] Name the page and path in the markup-not-found messages of Component The messages only had the component's class and id, so with several components sharing an id such as 'feedback' it was impossible to tell which one failed. They now also name the page class and the page-relative path of the component. When the failure happens while an Ajax update renders, the message adds a hint that the parent's markup may not contain the component. Only the message text changes. The exception types are unchanged. GitHub issue #1957 Generated-by: Claude Code (Claude Sonnet 5.5, claude-sonnet-5-5) Co-Authored-By: Claude Sonnet 5.5 --- .../wicket/ComponentMarkupNotFoundTest.java | 49 +++++++++++++++++++ .../java/org/apache/wicket/Component.java | 30 +++++++++++- 2 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 wicket-core-tests/src/test/java/org/apache/wicket/ComponentMarkupNotFoundTest.java diff --git a/wicket-core-tests/src/test/java/org/apache/wicket/ComponentMarkupNotFoundTest.java b/wicket-core-tests/src/test/java/org/apache/wicket/ComponentMarkupNotFoundTest.java new file mode 100644 index 0000000000..8d93e0db07 --- /dev/null +++ b/wicket-core-tests/src/test/java/org/apache/wicket/ComponentMarkupNotFoundTest.java @@ -0,0 +1,49 @@ +/* + * 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.wicket; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.apache.wicket.markup.MarkupNotFoundException; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.util.tester.WicketTestCase; +import org.junit.jupiter.api.Test; + +/** + * Tests the message of the exception thrown when a component has no markup. + */ +class ComponentMarkupNotFoundTest extends WicketTestCase +{ + @Test + void messageNamesPageAndPath() + { + MockPageWithOneComponent page = new MockPageWithOneComponent(); + page.add(new Label(MockPageWithOneComponent.COMPONENT_ID, "text")); + tester.startPage(page); + + // the component is not in the page markup, like one added to an Ajax update + Label missing = new Label("missing", "text"); + page.add(missing); + + MarkupNotFoundException e = assertThrows(MarkupNotFoundException.class, missing::render); + + assertThat(e.getMessage()).contains("Markup not found for Component") + .contains("page: " + MockPageWithOneComponent.class.getName()) + .contains("path: missing"); + } +} diff --git a/wicket-core/src/main/java/org/apache/wicket/Component.java b/wicket-core/src/main/java/org/apache/wicket/Component.java index 40cca3f066..4e58fa418b 100644 --- a/wicket-core/src/main/java/org/apache/wicket/Component.java +++ b/wicket-core/src/main/java/org/apache/wicket/Component.java @@ -32,6 +32,7 @@ import org.apache.wicket.authorization.strategies.page.SimplePageAuthorizationStrategy; import org.apache.wicket.behavior.Behavior; import org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler; +import org.apache.wicket.core.request.handler.IPartialPageRequestHandler; import org.apache.wicket.core.request.handler.ListenerRequestHandler; import org.apache.wicket.core.request.handler.PageAndComponentProvider; import org.apache.wicket.core.util.lang.WicketObjects; @@ -2129,6 +2130,31 @@ public final void render() } } + /** + * Builds the message for a component that has no markup. It names the page and the + * page-relative path of the component, because the id alone is ambiguous in a large page. + * + * @param prefix + * the start of the message + * @return the message + */ + private String markupNotFoundMessage(String prefix) + { + StringBuilder message = new StringBuilder(prefix).append(toString()); + Page page = findPage(); + if (page != null) + { + message.append(", page: ").append(page.getClass().getName()).append(", path: ") + .append(getPageRelativePath()); + } + if (getRequestCycle().find(IPartialPageRequestHandler.class).isPresent()) + { + message.append(". The component is rendered as part of an Ajax update. Its parent's markup may not" + + " contain it, for example because it was invisible when the page was first rendered."); + } + return message.toString(); + } + /** * Performs a render of this component as part of a Page level render process. */ @@ -2138,7 +2164,7 @@ private void internalRender() IMarkupFragment markup = getMarkup(); if (markup == null) { - throw new MarkupNotFoundException("Markup not found for Component: " + toString()); + throw new MarkupNotFoundException(markupNotFoundMessage("Markup not found for Component: ")); } // MarkupStream is an Iterator for the markup @@ -2288,7 +2314,7 @@ protected final void internalRenderComponent() final IMarkupFragment markup = getMarkup(); if (markup == null) { - throw new MarkupException("Markup not found. Component: " + toString()); + throw new MarkupException(markupNotFoundMessage("Markup not found. Component: ")); } final MarkupStream markupStream = new MarkupStream(markup); From 1618c1cb7313b0561e666b4f7b1bb40e7e06367a Mon Sep 17 00:00:00 2001 From: Andrea Del Bene Date: Mon, 30 Nov 2026 13:14:38 +0100 Subject: [PATCH 2/2] Refactor markupNotFoundMessage method implementation Replaced the existing markupNotFoundMessage method with a new implementation that builds a message for components without markup, including page and path details. --- .../java/org/apache/wicket/Component.java | 33 +++++-------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/wicket-core/src/main/java/org/apache/wicket/Component.java b/wicket-core/src/main/java/org/apache/wicket/Component.java index 28c9d07b4d..8dd50e6cf3 100644 --- a/wicket-core/src/main/java/org/apache/wicket/Component.java +++ b/wicket-core/src/main/java/org/apache/wicket/Component.java @@ -2130,6 +2130,14 @@ public final void render() } } + /** + * Builds the message for a component that has no markup. It names the page and the + * page-relative path of the component, because the id alone is ambiguous in a large page. + * + * @param prefix + * the start of the message + * @return the message + */ private String markupNotFoundMessage(String prefix) { StringBuilder message = new StringBuilder(prefix).append(toString()); @@ -2157,31 +2165,6 @@ private String markupNotFoundMessage(String prefix) return message.toString(); } - /** - * Builds the message for a component that has no markup. It names the page and the - * page-relative path of the component, because the id alone is ambiguous in a large page. - * - * @param prefix - * the start of the message - * @return the message - */ - private String markupNotFoundMessage(String prefix) - { - StringBuilder message = new StringBuilder(prefix).append(toString()); - Page page = findPage(); - if (page != null) - { - message.append(", page: ").append(page.getClass().getName()).append(", path: ") - .append(getPageRelativePath()); - } - if (getRequestCycle().find(IPartialPageRequestHandler.class).isPresent()) - { - message.append(". The component is rendered as part of an Ajax update. Its parent's markup may not" - + " contain it, for example because it was invisible when the page was first rendered."); - } - return message.toString(); - } - /** * Performs a render of this component as part of a Page level render process. */