语法错误导致空白页

发布于 2024-09-06 11:43:06 字数 1035 浏览 3 评论 0原文

我是检票口新手,正在努力让一些事情发挥作用。
让我很烦恼的一件事是,每当页面上存在语法错误时,我都会得到一个空白(0 个文本字符)页面。

条纹示例:
Test.html

header stuff: doctype ... html ... head ... body ...
  <span wicket:id="msgTest" id="message">MSG</span>
footer stuff: /body ... /html

Test.java

public class Test extends WebPage {
    public Test() {
        add(new Label("msgTest", "Hello, World!"));
    }
}

这将按预期输出页面。
现在,让我们引入一个错误:

header stuff: doctype ... html ... head ... body ...
  <span wicket:id="msgTest2" id="message">MSG</span>
footer stuff: /body ... /html

我将标签 ID 更改为与源文件期望的不同的内容。
如果我运行此代码,我会得到已经提到的空白页。
然而,对于具有此类语法错误的页面的每个请求,我都会在日志文件中收到大约 1000 多行的错误报告。这个错误报告基本上只是 wicket 生成的描述错误的 html 页面。
这让我想知道为什么 wicket 不显示错误内容而不是空白页面。我对 wicket 不太有经验,但对我来说,不知何故,wicket 似乎在渲染自己的错误页面代码时遇到了麻烦。

很高兴知道如何使用 wicket 查找语法错误。
阅读 1000 多行错误报告来查找像放错位置的字符这样的小错误似乎有点乏味。

预先感谢您引导我走向正确的方向:)

PS:
检票口版本:1.4.9
阶段:发展

I am new to wicket and trying to get some things working.
One thing that annoys me a lot is that I get a blank (0 chars of text) page whenever there is a syntax error on a page.

Striped down example:
Test.html

header stuff: doctype ... html ... head ... body ...
  <span wicket:id="msgTest" id="message">MSG</span>
footer stuff: /body ... /html

Test.java

public class Test extends WebPage {
    public Test() {
        add(new Label("msgTest", "Hello, World!"));
    }
}

This will output the page as expected.
Now, lets introduce an error:

header stuff: doctype ... html ... head ... body ...
  <span wicket:id="msgTest2" id="message">MSG</span>
footer stuff: /body ... /html

I changed the label-id to something different then what the source-file expects.
If I run this code I get the already mentioned blank page.
However, for every request to a page with such a syntax error I get an error report in the log-file of around 1000+ lines. This error-report is basically just wicket-generated html of a page which describes the error.
This makes me wonder why wicket isn't displaying the error-stuff instead of the blank page. I'm not very experienced with wicket but to me it somehow looks like wicket is having trouble rendering its own error-page code.

It would be nice to know how one goes about finding syntax-errors with wicket.
Reading through a 1000+ line error-report for a small error like a misplaced character seems a bit tedious.

Thanks in advance for guiding me into the right direction :)

PS:
wicket-version: 1.4.9
stage: development

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

昔梦 2024-09-13 11:43:06

我无法确认这种行为。我访问 http://wicket.apache.org/quickstart.html 并创建了一个快速入门。将 wicket id 从“message”更改为“message1”,并在 jetty 中获得了一个很好的描述性页面:

WicketMessage: Unable to find component with id 'message' in [Page class = com.mycompany.HomePage, id = 0, version = 0]. This means that you declared wicket:id=message in your markup, but that you either did not add the component to your page at all, or that the hierarchy does not match.

您是如何创建项目的?

I can not confirm that behavior. I went to http://wicket.apache.org/quickstart.html and created a quickstart. Changed the wicket id from 'message' to 'message1' and got a nice descriptive page in jetty:

WicketMessage: Unable to find component with id 'message' in [Page class = com.mycompany.HomePage, id = 0, version = 0]. This means that you declared wicket:id=message in your markup, but that you either did not add the component to your page at all, or that the hierarchy does not match.

How did you create your project?

听你说爱我 2024-09-13 11:43:06

我喜欢做的是使用 WicketTester 编写单元测试,至少验证事物是否呈现,并且通常还编写断言来检查组件。 然后,如果像您的示例中那样,

@Test
public void testMessageLabel(
    WicketTester tester = new WicketTester();
    tester.startPage(Test.class);
    tester.assertLastRenderedPage(Test.class);
    tester.assertComponent("msgTest", Label.class);
    tester.assertLabel("msgTest", "Hello, World!");
)

代码包含“msgTest”并且html包含“msgTest2”,那么您至少会得到测试失败,而不是在部署后将其视为失败应用程序的一部分。

这当然不是一个完整的解决方案,因为此错误将使页面的任何渲染测试失败,并且特定的失败只会在测试结果中给出很长的错误消息,但至少您不必搜索日志文件。

What I like to do is write unit tests with WicketTester to at least verify that things render, and usually also write assertions to check the components. Something along the lines of

@Test
public void testMessageLabel(
    WicketTester tester = new WicketTester();
    tester.startPage(Test.class);
    tester.assertLastRenderedPage(Test.class);
    tester.assertComponent("msgTest", Label.class);
    tester.assertLabel("msgTest", "Hello, World!");
)

Then if as in your example the code contains "msgTest" and the html contains "msgTest2" you at least get a test failure instead of seeing it as part of a failing app after deploy.

It's certainly not a complete solution, since this error will make any rendering test for the page fail and the particular failure will just give a long error message in the test result, but at least you don't have to search log files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文