用 MVP 替换嵌套 UIBinder 结构中的标记/错误处理

发布于 2024-12-10 02:15:51 字数 475 浏览 0 评论 0原文

我使用 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 技术交流群。

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

发布评论

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

评论(2

深爱成瘾 2024-12-17 02:15:51

您可以让 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 a HTMLPanel getErrorPanel() method). The latter is closest to what you're talking about. Have Form1 and Form2 both implement HasErrorPanel and then call getErrorPanel().add(subWidget).

清晨说晚安 2024-12-17 02:15:51

这是我得出的结论。也许它对其他人有帮助。
它基于 Riley Lark 的推荐 - 顺便说一句,感谢 Riley。

这里的 RegistrationPresenter 负责注册过程并向用户显示注册表单。错误消息应尽可能靠近错误发生的位置显示。

没有错误 http://www.mikemitterer.at/fileadmin/stacktrace_imagehosting/screenshot- 778.jpg

发生错误:
弹出错误 http://www.mikemitterer.at/fileadmin/stacktrace_imagehosting/screenshot -780.jpg

现在,我粗略地描述了我如何实现此行为:

public class RegistrationPresenter implements Presenter {

public interface Display extends StatusDisplay, HasMessageBlock {
    Widget asWidget();

    void setData(RegistrationTO registration);
}

private final Display   display;
private final EventBus  eventBus;
    ...

如您所见,它的 Display 实现了 HasMessageBlock:

public interface HasMessageBlock {
void showMessage(Message message);

void hideMessage();
    }

存在一个UIBinder-Widget MessageBlock (MessageBlock.ui.xml + MessageBlock.java)
(消息块将在其构造函数中变为不可见)

    <g:HTMLPanel styleName="errorblock" ui:field="messageblock">
        <div id="errorMsg" class="flurid">
            <div class="row">
                <div class="column width_15/16">
                    <h3><ui:msg key="errorblock.headline">An error occurred...</ui:msg></h3>
                </div>
                <div class="column orientation-right islink width_1/16">
                    <g:Image resource='{res.xgray}' ui:field="image" />
                </div>
     ...

注册小部件现在包含 MessageBlock

<g:HTMLPanel styleName="registration" ui:field="panel">
    <div class="uniForm maxgrid700">
        <h1>
            <ui:msg key="registration.headline">Registration</ui:msg>
        </h1>
        <c:MessageBlock ui:field="messageblock"/>
        <div class="ctrlHolder">
            <p class="label">
                <em></em>
                <ui:msg key="registration.name">Name:</ui:msg>
            </p>
     ...

现在,如果有人触发一条消息,则

eventbus.fireEvent(new MessageEvent(new MessageImpl(Message.MESSAGETYPE.ERROR, "Server Error Message")));

每个具有“HasMessageBlock”的 Display 的 Presenter 都可以处理/显示该消息:

        eventBus.addHandler(MessageEvent.TYPE, new MessageEventHandler() {

        @Override
        public void execute(final MessageEvent event) {
            display.showMessage(event.getMessage());
        }
    });

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:

public class RegistrationPresenter implements Presenter {

public interface Display extends StatusDisplay, HasMessageBlock {
    Widget asWidget();

    void setData(RegistrationTO registration);
}

private final Display   display;
private final EventBus  eventBus;
    ...

as you can see it's Display implements HasMessageBlock:

public interface HasMessageBlock {
void showMessage(Message message);

void hideMessage();
    }

There exists a UIBinder-Widget MessageBlock (MessageBlock.ui.xml + MessageBlock.java)
(messageblock will be turned to invisible in it's constructor)

    <g:HTMLPanel styleName="errorblock" ui:field="messageblock">
        <div id="errorMsg" class="flurid">
            <div class="row">
                <div class="column width_15/16">
                    <h3><ui:msg key="errorblock.headline">An error occurred...</ui:msg></h3>
                </div>
                <div class="column orientation-right islink width_1/16">
                    <g:Image resource='{res.xgray}' ui:field="image" />
                </div>
     ...

The Registration-Widget now includes MessageBlock

<g:HTMLPanel styleName="registration" ui:field="panel">
    <div class="uniForm maxgrid700">
        <h1>
            <ui:msg key="registration.headline">Registration</ui:msg>
        </h1>
        <c:MessageBlock ui:field="messageblock"/>
        <div class="ctrlHolder">
            <p class="label">
                <em></em>
                <ui:msg key="registration.name">Name:</ui:msg>
            </p>
     ...

Now, if someone fires a Message

eventbus.fireEvent(new MessageEvent(new MessageImpl(Message.MESSAGETYPE.ERROR, "Server Error Message")));

every Presenter which has "HasMessageBlock" for it's Display can process/display the message:

        eventBus.addHandler(MessageEvent.TYPE, new MessageEventHandler() {

        @Override
        public void execute(final MessageEvent event) {
            display.showMessage(event.getMessage());
        }
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文