我的mainpresenter中有内容插槽,如何在应用程序加载时将主播放器放在一个插槽中,将菜单插槽放在另一个插槽中?
或者不可能?
提前致谢.
我使用GWT-Platform和GWT-Bootstrap框架构建了一个使用Google Web Toolkit的webapp .在我尝试实现弹出窗口之前,它几乎完美无瑕.这些框架的弹出窗口似乎完全不同.
GWT-Platform期望弹出窗口小部件本身是com.google.gwt.user.client.ui.PopupPanel
使用GWTP RevealRootPopupContentEvent.fire(source, content)
或演示者addToPopupSlot(child)
方法时的实例.
GWT-Bootstrap的模态与添加到底层面板的任何其他窗口小部件一样使用,但我的目标是拥有一个单独的演示者和视图,并可能使用AsyncProvider异步获取它.
我试图将它作为PresenterWidget使用addToSlot(slot, content)
并显示它,但它看起来不太正确.并非所有样式都以这种方式应用,并且关闭图标(×)不起作用.
我想我并不是第一个尝试这样做的人,所以也许有人想出了一个合适的方法让它发挥作用.
谢谢!
有很多像这样的问题.我经历了大部分但实际上没有,但我无法得出任何答案:
我的一个GWT/GWTP类中有一个奇怪的问题.
该类使用Eclipse编译器编译良好,但使用javac编译器(Maven)失败.
//additional imports
import com.gwtplatform.mvp.client.PresenterWidget;
import com.gwtplatform.mvp.client.View;
public class MyPresenter extends PresenterWidget<MyPresenter.MyView> {
public interface MyView extends View {
}
some code
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用maven编译时,我收到以下错误:
找不到符号符号:class View
View是指包中的View
接口com.gwtplatform.mvp.client
.
我有其他类看起来一样,工作正常.
奇怪的是,如果我改变了导入的顺序,或者我指定了View
接口的确切包,它在maven中编译时没有任何问题.
具体来说,我移动了导入com.gwtplatform.mvp.client.View
import com.gwtplatform.mvp.client.View;
//additional imports
import com.gwtplatform.mvp.client.PresenterWidget;
Run Code Online (Sandbox Code Playgroud)
前段时间我遇到了类似的问题,类之间的循环继承问题引用了内部类(在eclipse中工作但在javac中没有).但是我不确定这是否是同样的问题.
我正在使用gwt-platform并尝试实现GWT的编辑器框架.但是我没有在演示者中得到它.网络上有一些答案,说我必须以某种方式将EditorDriver注入Presenter,但我不知道如何做到这一点......
目前我尝试了这个没有成功:
public class MyPresenter extends Presenter<MyPresenter.MyView, MyPresenter.MyProxy> implements MyUiHandlers {
public interface MyView extends View, HasUiHandlers<MyUiHandlers>, Editor<MyModel> {}
@ProxyStandard
@NameToken(NameTokens.myPage)
@NoGatekeeper
public interface MyProxy extends ProxyPlace<MyPresenter> {}
interface Driver extends SimpleBeanEditorDriver<MyModel, MyView> {}
private Driver editorDriver;
DispatchAsync dispatcher;
@Inject
public MyPresenter(EventBus eventBus, MyView view, MyProxy proxy, DispatchAsync dispatcher) {
super(eventBus, view, proxy);
getView().setUiHandlers(this);
this.dispatcher = dispatcher;
MyModel m = new MyModel();
m.setId(1L);
m.setUsername("username");
m.setPassword("password");
editorDriver = GWT.create(Driver.class);
editorDriver.initialize(this.getView());
editorDriver.edit(m);
}
...
}
Run Code Online (Sandbox Code Playgroud)
如果我明确指定ViewImplementation,它可以工作,但这不是MVP应该工作的方式:
interface Driver extends SimpleBeanEditorDriver<MyModel, MyViewImpl> {} …
Run Code Online (Sandbox Code Playgroud) 我正在使用GWTP,添加一个Contract层来抽象Presenter和View之间的知识,我对GWTP的结果非常满意.我正在用Mockito测试我的主持人.
但随着时间的推移,我发现通过测试很难保持干净的演示者.我做了一些改进的改进,但我还是不满意.
我发现以下内容是问题的核心:我的演示者经常需要异步调用,或者通常使用回调调用对象方法来继续我的演示者流程(它们通常是嵌套的).
例如 :
this.populationManager.populate(new PopulationCallback()
{
public void onPopulate()
{
doSomeStufWithTheView(populationManager.get());
}
});
Run Code Online (Sandbox Code Playgroud)
在我的测试中,我结束了验证被模拟的PopulationManager对象的population()调用.然后在doSomeStufWithTheView()方法上创建另一个测试.
但我很快发现这是糟糕的设计:任何改变或重构都会破坏我的大量测试,并迫使我从其他人开始创建,即使演示者功能没有改变!另外,我没有测试回调是否真正符合我的要求.
所以我尝试使用mockito doAnswer方法来破坏我的演示者测试流程:
doAnswer(new Answer(){
public Object answer(InvocationOnMock invocation) throws Throwable
{
Object[] args = invocation.getArguments();
((PopulationCallback)args[0]).onPopulate();
return null;
}
}).when(this.populationManager).populate(any(PopulationCallback.class));
Run Code Online (Sandbox Code Playgroud)
我考虑到它的代码更简洁(并且内部更少依赖于arg位置):
doAnswer(new PopulationCallbackAnswer())
.when(this.populationManager).populate(any(PopulationCallback.class));
Run Code Online (Sandbox Code Playgroud)
因此,在模拟人口管理器时,我仍然可以测试我的演示者的流程,基本上是这样的:
@Test
public void testSomeStuffAppends()
{
// Given
doAnswer(new PopulationCallbackAnswer())
.when(this.populationManager).populate(any(PopulationCallback.class));
// When
this.myPresenter.onReset();
// Then
verify(populationManager).populate(any(PopulationCallback.class)); // That was before
verify(this.myView).displaySomething(); // Now I can do that.
}
Run Code Online (Sandbox Code Playgroud)
我想知道它是否很好地使用了doAnswer方法,或者它是否有代码味道,并且可以使用更好的设计?
通常,我的演示者倾向于使用其他对象(如某些Mediator Pattern)并与视图进行交互.我有一些主持人有几百(~400)行代码.
再一次,它是不良设计的证明,还是主持人冗长是正常的(因为它使用其他对象)?
有没有人听说过一些使用GWTP并干净地测试其主持人的项目?
我希望我能以全面的方式解释.
先感谢您.
PS:我对Stack Overflow很新,加上我的英语仍然缺乏,如果我的问题需要改进,请告诉我.
我有RPC服务,返回从Event(抽象)扩展的GameEvent类型的对象.当我在客户端获取对象时,从Event(eventId,copyEventId,gameTimeGMT)继承的所有属性都设置为,null
而在服务器端,这些属性具有值.
public class GameEvent extends Event implements IsSerializable {
private String homeTeam;
private String awayTeam;
public GameEvent() {
}
}
// Annotation are from the twig-persist framework which should not
// impact the serialization process.
public abstract class Event implements IsSerializable {
@Key
protected String eventId;
@Index
protected String copyEventId;
protected Date gameTimeGMT;
protected Event() {
}
}
Run Code Online (Sandbox Code Playgroud)
更新:我使用gwt-platform框架(MVP实现).这是对服务客户端的调用.在result.getGE()
返回GameEvent对象,但与null
属性.
dispatcher.execute(
new GetFormattedEventAction(
id),
new AsyncCallback<GetFormattedEventResult>() {
@Override
public void onFailure(Throwable caught) {
caught.printStackTrace();
} …
Run Code Online (Sandbox Code Playgroud) 我需要对div css做一些调整.但我无法在方法onBind()或onReveal()上执行此操作,因为调用此两个方法时不会加载html.
所以我想知道一些方法来自动调用一个方法,当我修改我的html(当一个Presenter被称为html必须修改,因为新的小部件将被添加)加载.
这是我必须调用的方法:
private void hidePopup(){
$(".olLayerGooglePoweredBy, .olLayerGoogleV3, .gmnoprint").
css(CSS.VISIBILITY.with
(com.google.gwt.dom.client.Style.Visibility.HIDDEN));
}
Run Code Online (Sandbox Code Playgroud) 有些示例会将不同类型的对象注入演示者,但我无法找到解释如何完成此操作的示例.
在Bootstrap-Code示例中,它们正在注入例如SecurityDelegate
对象.
同样在Gatekeeper示例中,我看到正在注入的东西,例如MyGatekeeper
,但这是如何完成的?
我想要的是首先检查用户是否登录,然后创建一个CurrentSession
对象或类似的东西.但是我怎么能传递/注入这个对象呢?
目前我正在初始化一个单身对象CurrentUser
,这是一种丑陋的imho.我想让GWTP支持运行,但是怎么样?
以这个CurrentSession
被注入网守的例子为例:
@DefaultGatekeeper
public class LoggedInGatekeeper implements Gatekeeper {
private final CurrentSession currentSession;
@Inject
LoggedInGatekeeper(CurrentSession currentSession) {
this.currentSession = currentSession;
}
@Override
public boolean canReveal() {
return currentSession.isLoggedIn();
}
}
Run Code Online (Sandbox Code Playgroud)
我怎么CurrentSession
在这里注射?
编译过程中可能是什么原因导致此错误?
我已经从这个原型https://github.com/ArcBees/Arcbees-Archetypes生成了项目,并且我只更改了一件事 - 将 GWT 更新到 2.8.0,将 GWTP 更新到 1.5.3。
[INFO] [ERROR] An internal compiler exception occurred
[INFO] com.google.gwt.dev.jjs.InternalCompilerException: Error constructing Java AST
[INFO] at com.google.gwt.dev.jjs.impl.GwtAstBuilder.translateException(GwtAstBuilder.java:3099)
[INFO] at com.google.gwt.dev.jjs.impl.GwtAstBuilder$AstVisitor.endVisit(GwtAstBuilder.java:352)
[INFO] at org.eclipse.jdt.internal.compiler.ast.AllocationExpression.traverse(AllocationExpression.java:670)
[INFO] at org.eclipse.jdt.internal.compiler.ast.Assignment.traverse(Assignment.java:260)
[INFO] at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.traverse(MethodDeclaration.java:347)
[INFO] at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1379)
[INFO] at com.google.gwt.dev.jjs.impl.GwtAstBuilder.process(GwtAstBuilder.java:3058)
[INFO] at com.google.gwt.dev.javac.CompilationStateBuilder$CompileMoreLater$UnitProcessorImpl.process(CompilationStateBuilder.java:141)
[INFO] at com.google.gwt.dev.javac.JdtCompiler$CompilerImpl.process(JdtCompiler.java:384)
[INFO] at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:470)
[INFO] at com.google.gwt.dev.javac.JdtCompiler.doCompile(JdtCompiler.java:985)
[INFO] at com.google.gwt.dev.javac.CompilationStateBuilder$CompileMoreLater.compile(CompilationStateBuilder.java:339)
[INFO] at com.google.gwt.dev.javac.CompilationStateBuilder.doBuildFrom(CompilationStateBuilder.java:580)
[INFO] at com.google.gwt.dev.javac.CompilationStateBuilder.buildFrom(CompilationStateBuilder.java:513)
[INFO] at com.google.gwt.dev.javac.CompilationStateBuilder.buildFrom(CompilationStateBuilder.java:499)
[INFO] at com.google.gwt.dev.cfg.ModuleDef.getCompilationState(ModuleDef.java:668)
[INFO] at com.google.gwt.dev.Precompile.precompile(Precompile.java:255)
[INFO] at com.google.gwt.dev.Precompile.precompile(Precompile.java:229)
[INFO] at …
Run Code Online (Sandbox Code Playgroud)