Thursday, November 29, 2012

CellTable, this.focus is not a function

Hi All
As workaround for editing NULL values in CellTable i've extended Column
All works nice till use of SingleSelectionModel
With selection model editing null values goes random, some values can be edited, some not, after few tries selection model stops responding
Related exception stack trace below:

[ERROR] com.google.gwt.core.client.JavaScriptException: (TypeError) @com.google.gwt.dom.client.Element::focus()([]): this.focus is not a function
[ERROR]     at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:249)
[ERROR]     at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
[ERROR]     at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:570)
[ERROR]     at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:298)
[ERROR]     at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
[ERROR]     at com.google.gwt.dom.client.Element$.focus$(Element.java)
[ERROR]     at com.google.gwt.cell.client.EditTextCell.resetFocus(EditTextCell.java:240)
[ERROR]     at com.google.gwt.cell.client.EditTextCell.resetFocus(EditTextCell.java:1)
[ERROR]     at com.google.gwt.user.cellview.client.AbstractCellTable.resetFocusOnCellImpl(AbstractCellTable.java:2575)
[ERROR]     at com.google.gwt.user.cellview.client.AbstractCellTable.resetFocusOnCell(AbstractCellTable.java:2193)
[ERROR]     at com.google.gwt.user.cellview.client.AbstractHasData$View$1.execute(AbstractHasData.java:290)
[ERROR]     at com.google.gwt.user.cellview.client.CellBasedWidgetImpl.resetFocus(CellBasedWidgetImpl.java:102)
[ERROR]     at com.google.gwt.user.cellview.client.AbstractHasData$View.resetFocus(AbstractHasData.java:287)
[ERROR]     at com.google.gwt.user.cellview.client.HasDataPresenter.resolvePendingState(HasDataPresenter.java:1374)
[ERROR]     at com.google.gwt.user.cellview.client.HasDataPresenter.access$3(HasDataPresenter.java:1062)
[ERROR]     at com.google.gwt.user.cellview.client.HasDataPresenter$2.execute(HasDataPresenter.java:984)
[ERROR]     at com.google.gwt.core.client.impl.SchedulerImpl$Task$.executeScheduled$(SchedulerImpl.java:50)
[ERROR]     at com.google.gwt.core.client.impl.SchedulerImpl.runScheduledTasks(SchedulerImpl.java:228)
[ERROR]     at com.google.gwt.core.client.impl.SchedulerImpl.flushFinallyCommands(SchedulerImpl.java:327)
[ERROR]     at com.google.gwt.core.client.impl.Impl.exit(Impl.java:266)
[ERROR]     at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:257)
[ERROR]     at sun.reflect.GeneratedMethodAccessor286.invoke(Unknown Source)
[ERROR]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]     at java.lang.reflect.Method.invoke(Method.java:601)
[ERROR]     at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
[ERROR]     at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
[ERROR]     at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
[ERROR]     at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
[ERROR]     at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
[ERROR]     at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
[ERROR]     at java.lang.Thread.run(Thread.java:722)

Example class for reproducing exception below:
public class GwtBugTest0 {

    // Entity
    class Man {
        String name;
        Date birth;
    }

    // column that renders [NONE] for null and is updater, also gives initial value for updater
    abstract class NoneColumn<T, V> extends Column<T, V> implements FieldUpdater<T, V> {
        V def;

        public NoneColumn(Cell<V> cell, V def) {
            super(cell);
            this.def = def;
            setFieldUpdater(this);
        }

        @Override
        public V getValue(T object) {
            V ret = getRawValue(object);
            return ret == null ? def : ret;
        }

        @Override
        public void render(Context context, T object, SafeHtmlBuilder sb) {
            if (getRawValue(object) == null)
                sb.appendHtmlConstant("[NONE]");
            else
                super.render(context, object, sb);
        }

        protected abstract V getRawValue(T c);
    }

    // CellTable
    class ManTable extends CellTable<Man> {

        public ManTable() {
            DateTimeFormat DTF = DateTimeFormat.getFormat("yyyy-MM-dd");
            Column<Man, String> nameColumn = new NoneColumn<Man, String>(new EditTextCell(), "") {
                @Override
                protected String getRawValue(Man c) {
                    return c.name;
                }

                @Override
                public void update(int index, Man object, String value) {
                    object.name = value;
                }
            };
            addColumn(nameColumn, "Name");

            Column<Man, Date> birthColumn = new NoneColumn<Man, Date>(new DatePickerCell(DTF), new Date()) {
                @Override
                protected Date getRawValue(Man c) {
                    return c.birth;
                }

                @Override
                public void update(int index, Man object, Date value) {
                    object.birth = value;
                }
            };
            addColumn(birthColumn, "Birth");
        }
    }

    public void test1() {
        List<Man> list = new ArrayList<Man>();
        Random r = new Random();
        for (int i = 0; i < 10; i++) {
            Man m = new Man();
            if (r.nextBoolean())
                m.name = "John " + i;
            if (r.nextBoolean())
                m.birth = new Date(r.nextLong());
            list.add(m);
        }
        ManTable table = new ManTable();
        table.setRowData(list);
        SingleSelectionModel<Man> selectionModel = new SingleSelectionModel<Man>();
        table.setSelectionModel(selectionModel);
        RootPanel.get().add(table);
    }
I would be very grateful if you could help me find workaround or correct way to implement desired behaviour
Thanks!
P.
 
 

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/S12fX3RcyJ8J.
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