Dear All
I am just a newbie, I don't know whether this is a place to report bug. If not, please tell me where should I put.
Seems CompositeCell only accept 2 child-Cells, otherwise, exceptions will be thrown in Development Mode.
If these 2 child-Cells are both ActionCells, it might trigger ActionCell's handler when you click even on the blank area of the CompositeCell.
=================================
EntryPoint:
class UserInfo{
String userName;
String userLevel;
String nickName;
String eMail;
String title;
Date createDate;
String body;
public UserInfo(String userName){
this.userName = "userName:" + userName;
this.userLevel = "userLevel:" + userName;
this.nickName = "nickName:" + userName;
this.eMail = "eMail:" + userName;
this.title = "title:" + userName;
this.createDate = new Date();
this.body = "body:" + userName;
}
}
List al = Arrays.asList(new UserInfo("1234"),new UserInfo("qwer"),
new UserInfo("asdf"),new UserInfo("zxcv"),
new UserInfo("uiop"),new UserInfo("hjkl"),
new UserInfo("vbmn"),new UserInfo("7890"),
new UserInfo("uytr"),new UserInfo("同济大学"));
List<HasCell<UserInfo, ?>> hasCells = new ArrayList<HasCell<UserInfo, ?>>();
hasCells.add(new HasCell<UserInfo, UserInfo>() {
private ActionCell cell4 = new ActionCell("ActionCell4",
new ActionCell.Delegate<UserInfo>(){
@Override
public void execute(UserInfo object) {
Window.alert("ActionCell cell4:username:"+object.userName);
}
}
);
@Override
public Cell getCell() {
return cell4;
}
@Override
public UserInfo getValue(UserInfo object) {
return object;
}
@Override
public FieldUpdater<UserInfo, UserInfo> getFieldUpdater() {
//Window.alert("ActionCell cell4");
return null;
}
});
hasCells.add(new HasCell<UserInfo, UserInfo>() {
private ActionCell cell5 = new ActionCell("ActionCell5",
new ActionCell.Delegate<UserInfo>(){
@Override
public void execute(UserInfo object) {
Window.alert("ActionCell cell5:createDate:"+object.getCreateDateFormated());
}
}
);
@Override
public Cell getCell() {
return cell5;
}
@Override
public UserInfo getValue(UserInfo object) {
return object;
}
@Override
public FieldUpdater<UserInfo, UserInfo> getFieldUpdater() {
//Window.alert("ActionCell cell5");
return null;
}
});
HelloWorldCompositeCell hwcc = new HelloWorldCompositeCell(hasCells);
CellList cl = new CellList(hwcc);
cl.setRowData(al);
RootPanel.get().add(cl);
=================================
public class HelloWorldCompositeCell extends CompositeCell<UserInfo> {
interface MyUiRenderer extends UiRenderer {
void render(SafeHtmlBuilder sb, UserInfo user);
}
private static MyUiRenderer renderer = GWT.create(MyUiRenderer.class);
public HelloWorldCompositeCell(List<HasCell<UserInfo, ?>> hasCells) {
super(hasCells);
}
@Override
public void render(Context context, UserInfo user, SafeHtmlBuilder sb) {
if (user == null) {
return;
}
renderer.render(sb, user);
sb.appendHtmlConstant("<table border=\"1\" width=\"100%\" cellspacing=\"0\"><tbody><tr><td width=\"25%\"></td>");
super.render(context, user, sb);
sb.appendHtmlConstant("</tr></tbody></table>");
}
@Override
protected <X> void render(Context context, UserInfo value,
SafeHtmlBuilder sb, HasCell<UserInfo, X> hasCell) {
if ((value == null) || (hasCell == null)) {
return;
}
Cell<X> cell = hasCell.getCell();
sb.appendHtmlConstant("<td>");
cell.render(context, hasCell.getValue(value), sb);
sb.appendHtmlConstant("</td>");
}
}
=================================
HelloWorldCompositeCell.ui.xml
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder">
<ui:with field='user' type='com.learn.client.GwtLearn25rc1.UserInfo'/>
<ui:style>
.floatLeft { float:left }
.floatRigth { float:right }
.authorInfo { width: 25%; background-color:pink; border: 1px solid red; }
.content { width: 75%;border: 1px solid black; }
.title { background-color:gray; }
.body { color:gray; }
.enabled { color:black; }
.disabled { color:gray; }
</ui:style>
<div>
<table border="1" width="100%" cellspacing="0">
<tr>
<td class='{style.authorInfo}'>
<div><h2><ui:text from='{user.getNickName}'/></h2></div>
hello, <span><ui:text from='{user.getUserName}'/></span>.
<span><ui:text from='{user.getUserLevel}'/></span>
<div><ui:text from='{user.geteMail}'/></div>
</td>
<td class='{style.content}'>
<div class='{style.title}'>
<span class='{style.floatRigth}'>
<ui:text from='{user.getCreateDateFormated}' />
</span>
<span>
<h3><ui:text from='{user.getTitle}'/></h3>
</span>
</div>
<div class='{style.body}'>
<ui:text from='{user.getBody}'/>
</div>
</td>
</tr>
</table>
</div>
</ui:UiBinder>
=================================
You will see every item in the CellList will be shown as a 2x2 table. In right-bottom grid, ActionCell4 and ActionCell5 are there. But when you click first row of the item, ActionCell4 will be triggered. when you click second row ot the item, even black area of the row, ActionCell5 will be triggered. I think it's a bug.
=================================
=================================
There is another problem.
If you give one more child-cell, not mater TextCell, ButtonCell or CheckboxCell, when you click exception will be thrown on Development Mode.
=================================
You can put this TextCell:
hasCells.add(new HasCell<UserInfo, String>() {
private TextCell cell3 = new TextCell(){};
@Override
public Cell getCell() {
return cell3;
}
@Override
public String getValue(UserInfo object) {
return object.eMail;
}
@Override
public FieldUpdater<UserInfo, String> getFieldUpdater() {
Window.alert("TextCell3");
return null;
}
});
=================================
You will get this exception:
23:09:26.062 [ERROR] [gwtlearn25rc1] Uncaught exception escaped
com.google.gwt.core.client.JavaScriptException: (TypeError) @com.google.gwt.core.client.impl.Impl::apply(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)([JavaScript object(30), JavaScript object(70), JavaScript object(905)]): Cannot read property 'nextSibling' of null
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:249)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:570)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:278)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:242)
at sun.reflect.GeneratedMethodAccessor204.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
at java.lang.Thread.run(Unknown Source)
=================================
=================================
But if you remove anyone from these 2 ActionCells, let only 1 child-cell exist in hasCells. For example, we only remain and click ActionCell5, you will get following exception.
23:14:31.177 [ERROR] [gwtlearn25rc1] Uncaught exception escaped
java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at com.google.gwt.cell.client.CompositeCell.onBrowserEvent(CompositeCell.java:139)
at com.google.gwt.user.cellview.client.CellList.fireEventToCell(CellList.java:360)
at com.google.gwt.user.cellview.client.CellList.onBrowserEvent2(CellList.java:462)
at com.google.gwt.user.cellview.client.AbstractHasData.onBrowserEvent(AbstractHasData.java:739)
at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351)
at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1307)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:570)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:278)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:242)
at sun.reflect.GeneratedMethodAccessor213.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
at java.lang.Thread.run(Unknown Source)
But if you click the first row of the item, ActionCell5 will be triggered.
Gong Min
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
No comments:
Post a Comment