我使用GWT uiBinder创建了一个小部件.它工作正常,直到我想第二次实例化的那一刻.在我第二次调用构造函数之后,它只返回XML中的原始描述,而构造函数(rootElement.add( new HTML( "panel1" ), leftId );)中的语句只是不起作用.它不会引发任何错误或警告.
请帮忙
Java类:
public class DashboardLayout extends Composite {
final String leftId = "boxLeft";
final String rightId = "boxRight";
interface DashboardLayoutUiBinder extends UiBinder<HTMLPanel, DashboardLayout> {
}
private static DashboardLayoutUiBinder ourUiBinder = GWT.create( DashboardLayoutUiBinder.class );
@UiField
HTMLPanel htmlPanel;
public DashboardLayout() {
HTMLPanel rootElement = ourUiBinder.createAndBindUi( this );
this.initWidget( rootElement );
rootElement.add( new HTML( "panel1" ), leftId );
rootElement.add( new HTML( "panel2" ), rightId );
}
}
Run Code Online (Sandbox Code Playgroud)
XML描述:
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
>
<g:HTMLPanel …Run Code Online (Sandbox Code Playgroud) 我想让这个工作:
@UiField
CheckBox showDeleted;
@UiHandler("showDeleted")
public void onShowDeletedClicked(ValueChangeEvent<Boolean> ev) {
...
}
Run Code Online (Sandbox Code Playgroud)
我从GWT编译器中得到这些错误:
Invoking generator com.google.gwt.uibinder.rebind.UiBinderGenerator
[WARN] The method 'getAssociatedType()' in 'ValueChangeEvent' does not return Type<? extends EventHandler>.
[ERROR] Parameter 'ValueChangeEvent' is not an event (subclass of GwtEvent).
Run Code Online (Sandbox Code Playgroud)
有谁知道是否可以让这个工作?现在我将手动添加一个处理程序,但@UIBinder版本更好.
这张图片正在显示,但无论我使用的宽度或高度值如何,我都无法调整大小.你有什么?谢谢.
<ui:with field='res' type='com.hellomvp.client.resources.MyResources'/>
<ui:style>
.fortaImage { width:'50px'; height:'50px';}
</ui:style>
<g:DockLayoutPanel unit='EM'>
<g:north size="10">
<g:FlowPanel>
<g:Image styleName='{style.fortaImage}' resource='{res.fortaLogo}'/>
<g:InlineLabel>FortaService</g:InlineLabel>
<g:ListBox></g:ListBox>
<g:InlineLabel>DateIn</g:InlineLabel>
<d:DateBox></d:DateBox>
<g:InlineLabel>DateOut</g:InlineLabel>
<d:DateBox></d:DateBox>
<g:Button>Cerca</g:Button>
</g:FlowPanel>
</g:north>
</g:DockLayoutPanel>
Run Code Online (Sandbox Code Playgroud) 为什么这个"代码"失败了
<g:DockPanel unit="px">
<g:south size="100">
<g:TextBox ui:field="host" text="localhost"/>
</g:south>
<g:south size="100">
<g:TextBox ui:field="port" text="3287"/>
</g:south>
</g:DockPanel>
Run Code Online (Sandbox Code Playgroud)
而这个
<g:HorizontalPanel>
<g:cell>
<g:TextBox ui:field="host" text="localhost"/>
</g:cell>
<g:cell>
<g:TextBox ui:field="port" text="3287"/>
</g:cell>
</g:HorizontalPanel>
Run Code Online (Sandbox Code Playgroud)
不?
附加信息:
堆栈跟踪
ERROR: Deferred binding failed for 'client.view.EnterPage.EnterPageUiBinder'; expect subsequent failures.
ERROR: Unable to load module entry point class client.Dbweb (see associated exception for details). java.lang.RuntimeException: Deferred binding failed for 'client.view.EnterPage$EnterPageUiBinder' (did you forget to inherit a required module?)
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:53)
at com.google.gwt.core.client.GWT.create(GWT.java:98)
at client.view.EnterPage.<clinit>(EnterPage.java:27)
at client.Dbweb.onModuleLoad(Dbweb.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) …Run Code Online (Sandbox Code Playgroud) 我有以下UiBinder代码:
...
<div>
<g:Label>Hello,</g:Label>
<g:Button ui:field="button" />
</div>
...
Run Code Online (Sandbox Code Playgroud)
现在我想设置div元素的样式,然后让它给它一个红色边框.据我所知,明确的方法是定义一个像这样的样式:
<ui:style>
.redborder {
border: 1px solid red;
}
...
</ui:style>
Run Code Online (Sandbox Code Playgroud)
所以代码总是看起来像这样:
...
<div styleName="{style.redborder}">
<g:Label>Hello,</g:Label>
<g:Button ui:field="button" />
</div>
...
Run Code Online (Sandbox Code Playgroud)
但在HTML页面中没有绘制红色边框.现在我用Firebug查看页面(或者你如何在Google Chrome中调用这个东西)并看到div元素具有正确的类名,但是borwser还找不到类.如果在另一方面,我把相同的样式元素放到按钮一切正常.
有没有人知道它的行为是什么?
此致,斯特凡
我已经开始了一个GWT项目,我决定试试UiBinder.我很难在UiBinder上面放置一个MVP模式.
当我使用GWT-pure-java时:我会使用Gin为我的演示者注入相应的视图.这是非常直接的,如果我想将一个id传递给演示者,那么我只需将一个id传递给演示者的构造函数.
与UiBinder不太直接.我几乎可以肯定我错过了一些东西,因为很多人都声称UiBinder和MVP是在天堂做的比赛......所以我希望能在这个问题上得到一些坚实的回答;-)
我在几个简单的GWT-UiBinder示例中看到的是,视图是由绑定器创建的,然后是:
@UIFactory方法构造演示者.使用第一种方法,如果在视图中构建演示者,如何将id传递给演示者?你会这样做view.getPresenter().setId(42);,然后主持人会去服务器获取一些信息,并要求视图显示它......闻起来很糟糕.
使用第二种方法,最终会得到一个非直观的对象图,其中不清楚谁是消费者,谁是生产者.此外,在视图需要来自演示者的信息(几乎所有用例都需要此信息)的情况下,人们会做什么:
//some code would create the presenter pass it the id and then call view.setPresenter
class MyView {
void setPresenter(MyPresenter p) {
this.presenter = p;
//OK now that i have my presenter how do I ask it to fetch data from the server.
//do i turn around and do: presenter.setView(this); and then the presenter takes
//over and uses the view to display the data?
}
}
Run Code Online (Sandbox Code Playgroud)
这同样很臭......很抱歉这篇长篇文章,并提前感谢...
我有一个任务是将复合小部件添加到主ui.xml文件中,但由于某种原因它不起作用.这是我的小部件代码:
public class MyClass extends Composite {
@UiTemplate("MyClass .ui.xml")
interface MyClassUiBinder extends UiBinder<Widget, MyClass > {
}
private static MyClassUiBinder uiBinder = GWT.create(MyClassUiBinder.class);
@UiField Label label;
public MyClass() {
initWidget(uiBinder.createAndBindUi(this));
} ...
Run Code Online (Sandbox Code Playgroud)
然后在我的主viewImpl.ui.xml类中:我声明了类包:
... xmlns:u="urn:com... client.view">
Run Code Online (Sandbox Code Playgroud)
然后是小部件本身:
<g:HTMLPanel ui:field="mainPanel" styleName="{style.mainPanel}">
<table align="center">
<tr>
<td align="center">
<u:MyClass/>
</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
我也尝试在viewImpl类中设置一个ui:field声明,但是我在编译时抛出了一个错误:
错误]在@UiField myClass中,模板字段和所有者字段类型不匹配:com.google.gwt.dom.client.Element不能分配给com ... client.view.MyClass
当我从viewImpl和它编译的ui.xml中取出@UiField声明时,但是在加载页面时窗口小部件没有显示.
我创建了另一个复合窗口小部件类,并尝试使用按钮窗口小部件复制它.
使用firebug我看到元素已经添加到主ui.xml页面,但它也没有显示,所以我的绑定不是完全完整的.
我在这里错过了什么?
我正在尝试使用GWT编写我的第一个项目.而且我不了解使用UiBinder实现GWT应用国际化的原则.我之前使用过JSP.我清楚地了解该技术的国际化:
<fmt:message key="myValue" />
Run Code Online (Sandbox Code Playgroud)
在GWT中,类似标签可以包含一些内容:
<ui:msg key="myKey" description="myDescription">My content</ui:msg>
Run Code Online (Sandbox Code Playgroud)
我不清楚.这个标签的内容是什么意思?有什么意义呢?我理解的所有数据都应该从.properties文件中获取.什么属性key和description手段?他们应该包含什么价值?
如果有人可以解释国际化在UiBinder中是如何运作的,我将非常感激.提前致谢!
我有两个自定义小部件Foo extends Composite和Bar.我想将它们嵌套在我的ui.xml中,如下所示:
<my:Foo width="100%" ui:field="myFoo">
<my:Bar label="someLabel"/>
</my:Foo>
Run Code Online (Sandbox Code Playgroud)
我希望可以调用某种方法Foo,addWidget或者某种方法.但是我收到以下错误:
Found unexpected child element Element <my:Bar label='someLabel'>
Run Code Online (Sandbox Code Playgroud)
我怎么能修好这个?是否可以将我的自定义小部件嵌套在ui.xml中?
我是GWT的新手.我在我的ui.xml中创建了一个包含Image的面板.我想根据某些条件更改该图像的URL,alt和标题.怎么做 ?
<g:Image url="images/document-statut-1.gif" title="My title" altText="My alt"></g:Image>
Run Code Online (Sandbox Code Playgroud)
日Thnx