在 WICKET 中显示错误时不添加所有组件
我有一个页面需要一个参数。如果这个参数没有通过,那么我想显示一条错误消息(“请传递参数'blah”),该消息将显示在FeedBackPanel中并退出。但是,如果我不附加所有组件,则 wicket 会出现错误,将客户端重定向到 Wicket 的错误页面。
有没有办法显示错误消息而不将所有项目添加到页面?有些项目是 ListViews 等......
I have a page that takes a single argument. If this argument is NOT passed, then I would like to display an error message ("please pass argument 'blah") which will be shown in a FeedBackPanel and bail out. However, if I do not attach all the components, then wicket has an error instead, redirecting the client to Wicket's error page.
Is there any way to display an error messages and NOT add all the items to a page? Some of the items are ListViews, etc...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果容器不可见,则不会验证其结构一致性(匹配子级的 id)。因此,只需将您的内容包装在某个容器中,如果未传递参数,则调用 container.setVisible(false) 。然后您可以立即返回,而不添加其子项,Wicket 不会抱怨:
HomePage.java
HomePage.html
If the a container is not visible, it's not verified for structural consistency (matching childrens' ids). So, just wrap your content in some container and call container.setVisible(false) if the parameter isn't passed. You may then return immediately, without adding its children, Wicket won't complain:
HomePage.java
HomePage.html
最简单的解决方案是完全显示不同的页面。
如果做不到这一点,您可以使用
Panel
来放入所有可选组件。像这样:
您的html将是
您也可以使用
`Fragment
,但我不这样做不推荐它,它不会给你很好的代码。The easiest solution is to display a different page altogether.
Failing that, you can use a
Panel
to put all your optional components in.Something like this:
And your html will be
You can also use
`Fragment
s, but I don't recommend it, it doesn't give you very nice code.我认为托加姆斯勋爵走在正确的道路上。
我偷了这个例子: http://apache-wicket.1842946.n4.nabble.com/Feedback-message-does-not-show-in-new-WebPage-td2993413.html
HTML 片段
Java 片段
调用 session.error() 的事实向页面添加了足够的内容,以了解 (a) 显示反馈面板和 (b) 使用提供的文本/模型在该面板中。
I think Lord Torgamus is on the right track.
I stole this example: http://apache-wicket.1842946.n4.nabble.com/Feedback-message-does-not-show-in-new-WebPage-td2993413.html
HTML fragment
<div wicket:id="fbpnlFeedbackPanel"/>
Java fragment
The fact that the session.error() is called adds enough stuff to the page to know to (a) show the feedback panel and (b) use the provided text/model in that panel.