用 MVP 替换嵌套 UIBinder 结构中的标记/错误处理
我使用 DockLayoutPanel 作为我的主面板。 根据我单击的菜单,我更改了 DLP 的中心部分。 例如,我更改为 form1.ui.xml 或 form2.ui.xml。 这两种形式都实现了一个“标记”来显示错误消息:
<g:HTMLPanel ui:field="messageblock"/>
我遵循 MVP 模式(我使用 EventBus 进行通信),到目前为止一切都运行良好。我唯一不明白的是如何替换消息块的内容。或者更具体地说如何从我的 MainPresenter 访问消息块。这个东西背后的主要思想是将错误处理捆绑在一个演示者中......
我正在寻找类似
final Panel panel = DockLayoutPanel.get("messageblock");
panel.add(subwidget);
我欣赏每一个提示的东西......
I am using DockLayoutPanel as my main panel.
Dependent of the menu I click I change the center-part of the DLP.
For example I change either to form1.ui.xml or to form2.ui.xml.
Both of these forms have a "marker" implemented to display an error message:
<g:HTMLPanel ui:field="messageblock"/>
I am following the MVP Pattern (I use EventBus for communication) and so far everything works great. The only thing I can't figure out is how to replace the content of messageblock. Or to be more concret how to get access to messageblock from my MainPresenter. The main idea behind this stuff is to bundle the error-handling in one presenter...
I am looking for something like
final Panel panel = DockLayoutPanel.get("messageblock");
panel.add(subwidget);
I appreciate every hint...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以让 Display 负责呈现错误(使用
renderError(Error)
方法创建一些接口),或者让 Display 返回一个 HTMLPanel,其他东西可以将错误呈现到其中(某个带有HTMLPanel getErrorPanel()
方法)。后者最接近你所说的。让 Form1 和 Form2 都实现HasErrorPanel
,然后调用getErrorPanel().add(subWidget)
。You could either make the Display responsible for rendering the error (make some interface with a
renderError(Error)
method) or make the Display return an HTMLPanel that something else can render the error into (some interface with aHTMLPanel getErrorPanel()
method). The latter is closest to what you're talking about. Have Form1 and Form2 both implementHasErrorPanel
and then callgetErrorPanel().add(subWidget)
.这是我得出的结论。也许它对其他人有帮助。
它基于 Riley Lark 的推荐 - 顺便说一句,感谢 Riley。
这里的 RegistrationPresenter 负责注册过程并向用户显示注册表单。错误消息应尽可能靠近错误发生的位置显示。
没有错误 http://www.mikemitterer.at/fileadmin/stacktrace_imagehosting/screenshot- 778.jpg
发生错误:
弹出错误 http://www.mikemitterer.at/fileadmin/stacktrace_imagehosting/screenshot -780.jpg
现在,我粗略地描述了我如何实现此行为:
如您所见,它的 Display 实现了 HasMessageBlock:
存在一个UIBinder-Widget MessageBlock (MessageBlock.ui.xml + MessageBlock.java)
(消息块将在其构造函数中变为不可见)
注册小部件现在包含 MessageBlock
现在,如果有人触发一条消息,则
每个具有“HasMessageBlock”的 Display 的 Presenter 都可以处理/显示该消息:
Here is the conclusion I came to. Maybe it helps someone else.
It's based on what Riley Lark recommended - Thanks to Riley btw.
RegistrationPresenter here is responsible for the registration process and shows a registration form to the user. The error-message should be displayed as close as possible to the place where the error occurred.
Without error http://www.mikemitterer.at/fileadmin/stacktrace_imagehosting/screenshot-778.jpg
An error occurred:
Error popped up http://www.mikemitterer.at/fileadmin/stacktrace_imagehosting/screenshot-780.jpg
Here now a rough description how I implemented this behavior:
as you can see it's Display implements HasMessageBlock:
There exists a UIBinder-Widget MessageBlock (MessageBlock.ui.xml + MessageBlock.java)
(messageblock will be turned to invisible in it's constructor)
The Registration-Widget now includes MessageBlock
Now, if someone fires a Message
every Presenter which has "HasMessageBlock" for it's Display can process/display the message: