如何在GWT或GWTP中检索当前演示者?
这是我的问题。我的标题演示者中有许多链接 Link1 - Link2 - Link3 - GuideDialogLink 例如,当用户停留在Link3中时&如果他们单击GuideDialogLink,它将显示一个对话框,其中的Gui3与用户停留在Link1或Link2中时的Gui1或Gui2不同 所以,我的问题是: 有没有办法检索当前演示者 如果我们知道哪个演示者是当前演示者,那么我们可以相应地调用GuideDialog,例如:如何在GWT或GWTP中检索当前演示者?,gwt,gwtp,Gwt,Gwtp,这是我的问题。我的标题演示者中有许多链接 Link1 - Link2 - Link3 - GuideDialogLink 例如,当用户停留在Link3中时&如果他们单击GuideDialogLink,它将显示一个对话框,其中的Gui3与用户停留在Link1或Link2中时的Gui1或Gui2不同 所以,我的问题是: 有没有办法检索当前演示者 如果我们知道哪个演示者是当前演示者,那么我们可以相应地调用GuideDialog,例如:GuideDialog myGD=new GuideDialog(0
GuideDialog myGD=new GuideDialog(0)代码>
-另一种解决方案是将公共静态int-currentLink
存储在实用程序
类中。当用户单击link1、link2或link3时,我们可以使用EventBus设置public static currentLink
以相应地设置&最终GuideDialog myGD=new GuideDialog(Utility.currentLink)代码>
但我不认为这个解决方案是优雅的,因为谷歌必须有一些功能,让我们知道我们在哪个当前页面
那么我怎样才能优雅地解决我的问题呢
编辑
好的,让我澄清一下。我正在使用GWTP创建我的Web应用程序
-首先,我使用eclipse生成HeaderPresenter。eclipse将创建(HeaderPresenter.java、HeaderView.java和HeaderView.ui.xml)。HeaderPresenter有4个超链接:link1、link2、link3和GuideDialogLink
-第二,我创建了Link1Presenter(Link1Presenter.java、Link1View.java、Link1View.ui.xml)。然后我创建了Link2Presenter(Link2Presenter.java、Link2View.java、Link2View.ui.xml)。然后我创建了Link3Presenter(Link3Presenter.java、Link3View.java、Link3View.ui.xml)
-第三,我使用setInSlot
将Link1Presenter、Link2Presenter、Link3Presenter嵌入或嵌套在HeaderPresenter中。这意味着当用户转到link1(例如:abc.com#link1)时,他们将看到4个超链接(link1、link2、link3、GuideDialogLink)。如果他们去link2(例如:abc.com#link2)或link3,他们还会看到4个超链接
-第四,我创建了GuideDialog.java扩展了DialogBox&在HeaderPresenter中,我有guideDialogLink.addClickHandler(newclickhandler(){GuideDialog myGD=newguidedialog(int whichLink);})代码>
因此,当用户处于link1、Link2或Link3中时,他们将看到GuideDialogLink right?&当他们单击向导对话框时,会弹出一个对话框,对吗
现在我的要求是,当用户在Link1中时&如果他们单击GuideDialogLink,将弹出一个对话框并显示一个Gui(上面有两个文本框)。当用户处于Link2中时&如果他们单击GuideDialogLink,将弹出一个对话框并显示另一个Gui(上面有两个标签)。当用户处于Link3中时&如果他们单击GuideDialogLink,将弹出一个对话框并显示另一个不同的Gui(上面有两个复选框)考虑一下我们有这样的功能:
一般视图
// defines what you can access from a View
interface GeneralDisplay extends Display {
}
// implements a View
class abstract GeneralView implements GeneralDisplay {
// **Edit**: here you code the corresponding GUI
public abstract Composite getDialogGUI();
}
// additional, if you need specific behavior in your linkX view
interface LinkDisplay1 extends GeneralDisplay {
}
// if all views are the same there's no need to implement LinkDisplayX
class LinkView1 extends GeneralView implements LinkDisplay1 {
@Override
public Composite getDialogGUI () {
// **Edit** here you code the DialogGUI
}
}
// other LinkViews ...
// a more generic presenter for all Links
class GeneralPresenter<D extends GeneralDisplay> extends DefaultPresenter<D> {
// some code here ...
// constructor, here you associate the corresponding display
public GeneralPresenter (D display, EventBus eventBus, DispatchAsync dispatch) {
super(display,eventBus,dispatch);
// some code here ...
}
public void onBind () {
registerHandler(display.getDialogBoxLink().addClickHandler ( new ClickHandler () {
doShowDialogGUI();
}));
}
public void doShowDialogGUI () {
// here you show the dialog box, you can access the corresponding view by:
// this.display
// **Edit** add some code here
display.getDialogBox().setWidget(display.getDialogGUI());
}
}
// Then you have the follogiwng
class LinkPresenter1<D extends GeneralDisplay> extends GeneralPresenter<D> {
// some code here ...
@Override
public void onBind () {
super.onBind(); // here is where the "real stuff" is binded
}
}
链接特定视图
// defines what you can access from a View
interface GeneralDisplay extends Display {
}
// implements a View
class abstract GeneralView implements GeneralDisplay {
// **Edit**: here you code the corresponding GUI
public abstract Composite getDialogGUI();
}
// additional, if you need specific behavior in your linkX view
interface LinkDisplay1 extends GeneralDisplay {
}
// if all views are the same there's no need to implement LinkDisplayX
class LinkView1 extends GeneralView implements LinkDisplay1 {
@Override
public Composite getDialogGUI () {
// **Edit** here you code the DialogGUI
}
}
// other LinkViews ...
// a more generic presenter for all Links
class GeneralPresenter<D extends GeneralDisplay> extends DefaultPresenter<D> {
// some code here ...
// constructor, here you associate the corresponding display
public GeneralPresenter (D display, EventBus eventBus, DispatchAsync dispatch) {
super(display,eventBus,dispatch);
// some code here ...
}
public void onBind () {
registerHandler(display.getDialogBoxLink().addClickHandler ( new ClickHandler () {
doShowDialogGUI();
}));
}
public void doShowDialogGUI () {
// here you show the dialog box, you can access the corresponding view by:
// this.display
// **Edit** add some code here
display.getDialogBox().setWidget(display.getDialogGUI());
}
}
// Then you have the follogiwng
class LinkPresenter1<D extends GeneralDisplay> extends GeneralPresenter<D> {
// some code here ...
@Override
public void onBind () {
super.onBind(); // here is where the "real stuff" is binded
}
}
演讲者
// defines what you can access from a View
interface GeneralDisplay extends Display {
}
// implements a View
class abstract GeneralView implements GeneralDisplay {
// **Edit**: here you code the corresponding GUI
public abstract Composite getDialogGUI();
}
// additional, if you need specific behavior in your linkX view
interface LinkDisplay1 extends GeneralDisplay {
}
// if all views are the same there's no need to implement LinkDisplayX
class LinkView1 extends GeneralView implements LinkDisplay1 {
@Override
public Composite getDialogGUI () {
// **Edit** here you code the DialogGUI
}
}
// other LinkViews ...
// a more generic presenter for all Links
class GeneralPresenter<D extends GeneralDisplay> extends DefaultPresenter<D> {
// some code here ...
// constructor, here you associate the corresponding display
public GeneralPresenter (D display, EventBus eventBus, DispatchAsync dispatch) {
super(display,eventBus,dispatch);
// some code here ...
}
public void onBind () {
registerHandler(display.getDialogBoxLink().addClickHandler ( new ClickHandler () {
doShowDialogGUI();
}));
}
public void doShowDialogGUI () {
// here you show the dialog box, you can access the corresponding view by:
// this.display
// **Edit** add some code here
display.getDialogBox().setWidget(display.getDialogGUI());
}
}
// Then you have the follogiwng
class LinkPresenter1<D extends GeneralDisplay> extends GeneralPresenter<D> {
// some code here ...
@Override
public void onBind () {
super.onBind(); // here is where the "real stuff" is binded
}
}
//所有链接的更通用的演示者
类GeneralPresenter扩展了DefaultPresenter{
//这里有一些代码。。。
//构造函数,在这里您将关联相应的显示
公共GeneralPresenter(D显示、EventBus EventBus、dispatch异步调度){
超级(显示、事件总线、调度);
//这里有一些代码。。。
}
公共void onBind(){
registerHandler(display.getDialogBoxLink().addClickHandler(新的ClickHandler)(){
doShowDialogGUI();
}));
}
公共void doShowDialogGUI(){
//在此显示对话框,您可以通过以下方式访问相应的视图:
//这是我的显示器
//**编辑**在此处添加一些代码
display.getDialogBox().setWidget(display.getDialogGUI());
}
}
//那么你就有了下面的答案
类LinkPresenter1扩展了GeneralPresenter{
//这里有一些代码。。。
@凌驾
公共void onBind(){
super.onBind();//这里是绑定“真实内容”的地方
}
}
对于您可以阅读的更多信息,这是一条极好的信息,它向您展示了MVP体系结构是如何工作的
*编辑:*我添加了一些额外的代码,用于检索相应的对话框GUI视图。我不理解您的问题:
当你点击一个链接时,你的位置会改变(PlaceTokenizer,controller等等)。因此,信息位于PlaceController(当前位置url)中
你可以从那里获取信息。如果您有一个ClientFactory,您可以从中获取PlaceController,并询问哪个是当前的Place对象
例如:
public P getCurrentPlace() {
return (P) commonClientFactory.getPlaceController().getWhere();
}
...
注意:
信息也在ActivityManager中(我不建议在您的案例中使用,因为您对更大的范围(地点)感兴趣,而不是:当前活动)我找到了答案,非常简单
首先,当打开一个新链接时,我们可以添加一个类似whichLink的参数。Exmy.com#link1;whichLink=link1
然后在HeaderPresenter中,当调用GuideDialog时,我们这样做
GuideDialogBox gDialogBox=new GuideDialogBox(placeManager.getCurrentPlaceRequest().getParameter("whichLink", "home"));
如果我错了,请纠正我,您需要的是将鼠标悬停在链接上,然后单击“显示对话框”按钮,对话框将显示与相应演示者关联的视图,对吗?不,当用户单击GuideDialogLink时,将弹出一个对话框,它不会打开新浏览器。因此,假设你在link1(my.com/link1)中,点击GuideDialogLink,那么你仍然在my.com/link1中,对话框将显示Gui1(比如1按钮和2文本框)。好的,现在你在my.com/link2&u单击GuideDialogLink,然后你仍然在my.com/link2&dialogbox将显示Gui2(可能有4个单选按钮+2个标签),因此,场景如下:我们有3个视图,每个视图与相应的演示者相关联。然后我们有:Link1-View1-Presenter1,等等。然后,如果您停留在Link1视图中,然后单击GuideDialogLink,您将显示Presenter1检索到的一些GUI。这是正确的吗?谢谢你的问题,是的,几乎正确,但是Gui可以是任何东西&不是Presenter1所必需的,但是Gui是基于Presenter1的。例如,演示者1是ab