同一模块中有多个入口点的问题 [英] Problem with multiple entry Points in the same module

查看:41
本文介绍了同一模块中有多个入口点的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一个模块中有多个入口点.

I have multiple entry points in the same module.

例如,我有一个主页入口点和一个管理员管理页面的入口点.

For example I have an Home entry point for the home page and an Admin entry point for the admin page.

<entry-point class='com.company.project.client.HomeModule'/> 
<entry-point class='com.company.project.client.AdminModule'/> 

我现在的设置方式 - 我需要在我的OnModuleLoad:

The way I am setup now - I need to check somt like this in my OnModuleLoad:

if((RootPanel.get("someHomeWidget")!=null)&& 
  (RootPanel.get("someOtherHomeWidget")!=null)) 
{ 
  // do the stuff 
} 

为了在 Home 时不执行 Admin Entrypoint页面打开,反之亦然.

in order the the Admin Entrypoint not to be executed when the Home page gets open and the other way around.

不做上面的检查还涉及到如果我有一个带有无论我注入什么,主页和管理页面中的名称都相同它在每个人身上出现两次.

Not doing the check above also involves that if I have a div with the same name in both the Home and Admin page whatever I am injecting in it shows up twice on each of them.

这在 1000 英里外很臭,显然是错误的:正确的是什么在人们的经验中如何做到这一点?

This stinks 1000 miles away and is obviously wrong: what's the correct way to do this in people experience?

任何帮助表示赞赏!

推荐答案

正确的方法是每个模块有一个入口点,将适当的小部件粘贴在适当的 div 中:

The correct way is to have a single entry point per module, that sticks the appropriate widgets in the appropriate divs:

RootPanel panel = RootPanel.get("someHomeWidget");
if (panel) panel.add(new HomeWidget());

panel = RootPanel.get("adminWidget");
if (panel) panel.add(new AdminWidget());

这样它只会扫描页面以查找您拥有的任何 div 并插入适当的小部件.因此,您的 HTML 页面决定了何时显示哪些小部件,并且 GWT 代码已准备好处理任何情况.上面没有什么不好的地方,这是你的入口点应该写的方式.

That way it just scans the page looking for any divs you have and inserts the appropriate widget. So your HTML page determines what widgets are displayed when and the GWT code is ready to handle any situation. There's nothing about the above that stinks, it's the way your entry point should be written.

另一种选择是,如果您的管理区域和正常区域完全不同(例如:您想在不同的时间加载它们),那么它们应该是单独的模块,具有单独的入口点.

The alternative is if your admin area and normally area are totally different (eg: you want to load them at separate times) then they should be separate modules, with separate entry points.

这篇关于同一模块中有多个入口点的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆