请给我示例GWT2.5应用程序以及2.5中的所有附加功能。请给我试用UiBinder增强功能。但它没有用。
请尽快回复我。它迫切需要
以下是代码,
package com.MyApp.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
public class MainEntryPoint implements EntryPoint {
/**
* Creates a new instance of MainEntryPoint
*/
public MainEntryPoint() {
}
/**
* The entry point method, called automatically by loading a module
* that declares an implementing class as an entry-point
*/
@Override
public void onModuleLoad() {
final MainViewClass mainView = new MainViewClass();
RootPanel.get().add(mainView);
}
}
package com.Rajaa.client;
import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.Cell.Context;
import com.google.gwt.cell.client.ValueUpdater;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.uibinder.client.UiRenderer;
import com.google.gwt.user.client.Window;
public class MyActionCell extends AbstractCell<String> {
interface MyUiRenderer extends UiRenderer {
void render(SafeHtmlBuilder sb, String name);
void onBrowserEvent(EmployeeMain o, NativeEvent e, Element p, String n);
}
private static MyUiRenderer renderer = GWT.create(MyUiRenderer.class);
@Override
public void render(Context context, String value, SafeHtmlBuilder builder) {
renderer.render(builder, value);
}
@Override
public void onBrowserEvent(Context context, Element parent, String value,
NativeEvent event, ValueUpdater<String> updater) {
renderer.onBrowserEvent(this, event, parent, value);
}
public MyActionCell() {
super("click");
}
@UiHandler("nameSpan")
void onNameGotPressed(ClickEvent event, Element parent, String name) {
Window.alert(name + " was pressed!");
}
}
package com.MyApp.client;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import java.util.Arrays;
import java.util.List;
public class MyMainView extends Composite {
@UiField
CellTable<Student> table;
private static EmployeeUiBinder uiBinder = GWT.create(EmployeeUiBinder.class);
interface EmployeeUiBinder extends UiBinder<Widget, MyMainView> {
}
public Employee() {
super.initWidget(uiBinder.createAndBindUi(this));
TextColumn<Student> nameColumn = new TextColumn<Student>() {
@Override
public String getValue(Student object) {
return object.name;
}
};
table.addColumn(nameColumn, "Name");
final TextColumn<Student> ageColumn = new TextColumn<Student>() {
@Override
public String getValue(Student object) {
return object.age;
}
};
table.addColumn(ageColumn, "Age");
final TextColumn<Student> addressColumn = new TextColumn<Student>() {
@Override
public String getValue(Student object) {
return object.address;
}
};
table.addColumn(addressColumn, "Address");
Column<Student, String> editColumn = new Column<Student, String>(new MyActionCell()) {
@Override
public String getValue(Student object) {
return "Edit";
}
};
table.addColumn(editColumn, "Edit");
table.setRowCount(DETAILS.size(), true);
table.setRowData(0, DETAILS);
}
private static class Student {
private final String name;
private final String age;
private final String address;
public Student(String name, String age, String address) {
this.name = name;
this.age = age;
this.address = address;
}
}
private static final List<Student> DETAILS = Arrays.asList(
new Student("xxx", "50", "vvvvvvvvv"),
new Student("xxxxxx", "37", "dfdfdfdf"),
new Student("xxxx", "52", "fvxfxcfxdf"));
@UiHandler("nameSpan")
void onNameGotPressed(ClickEvent event) {
Window.alert("Yes!");
}
}
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:h="urn:import:com.google.gwt.user.cellview.client">
<ui:with field='name' type='java.lang.String'/>
<ui:style>
</ui:style>
<g:HTMLPanel>
<h:CellTable ui:field="table"/>
<g:Button ui:field='nameSpan'><ui:text from='{name}'/></g:Button>.
</ui:UiBinder>
提前致谢, Gnik
答案 0 :(得分:2)
Google Web Toolkit文档已使用最新版本(目前为2.5版)进行了更新。正如你所说,UiBinder有了新的改进。
根据Google博文What's new in GWT 2.5:
GWT 2.5为UiBinder添加了扩展,允许它支持Cell渲染和事件处理。特别是,这种设计使UiBinder能够生成UiRenderer实现,以帮助呈现SafeHtml,并将事件分派给@UiHandler标记指定的方法。有关详细信息,请参阅为单元格呈现HTML。
我们还介绍了IsRenderable / RenderablePanel类型。当应用程序而不是HTMLPanel使用它们时,它们可以显着缩短渲染时间并减少复杂UiBinder UI的延迟。
文档显示了2.5中有关该功能的多个示例。您可以在此处查看示例:Rendering HTML for Cells。