Repaint removing field focus in a table

Hey.

I got a table which has a field factory and a few generated columns. a bean item container is used to populate the table straight from pojos. the table is editable and has write through.

The problem I experience is that I get a table repaint when I change a value in the table and click on the next field. The repaint causes the field in the table to lose focus. This means that i have to click the next field twice to get the focus to the next field, and makes the use of tab completely useless.

Is there any way that I would not lose the focus of the fields? What more info should I supply so that you can figure this out?

The first tip I got was that the fieldfactory should not create new fields every time it is called. I created a map where all the fields are stored and returned if they exists, but it did not help.

I’m going to guess:

Your fields are immediate, causing a change to the datasource, which in turn tells the table it’s been updated, causing the table to redraw since the generated columns might need an update.

Removing the immediateness should do the trick - there are some samples with this kind of behavior, for instance http://toolkit.itmill.com/demo/sampler/#Components/Table%20(Grid)/TableRowStyling (click ‘edit’ and try it).

Hope this helps…?

Best Regards,
Marc

Hey Marc.

Well yeah, true. Removing immediate will fix the problem, but as you said the generatedColumn needs that update. Isn’t there any way to change the container, so that the generated labels are only repainted, and not the whole table? We kinda need both immediate and tab.

In order to do this, Table would at least need to cache the previously generated components, to see if they change. Currently it does not.

Theoretically, it might be possible to ‘trick’ table into thinking that no change has occurred (by not emitting an event), and just update the previously generated components, but this would require some strange connection between the container and the generated components, and I would not recommend it.

On the other hand, it would be nice if the scenario you describe would work w/o any workarounds - moving focus around is a quite common usecase…
TestCase + ticket, perhaps? I really can’t say how hard this is to fix w/o looking at the problem more closely, sorry…

Best Regards,
Marc

Ok, thinking about this some more, it seems to me that it should actually work, provided the FieldFactory really returns the same instance.

Of course this might be broken, but a sanity check still: are you absolutely sure (verify) that the Field instances are the same after attempting to move the focus?

Best Regards,
Marc

new HashMap<Object, Map><Object, Field>&gt();
where Object 1 is item id, Object 2 is property id and Field is the field.

fieldfactory looks like this.


    @Override
    public Field createField(Container container, Object itemId,
            Object propertyId, Component uiContext) {

        // Only return the field if it has already been created once
        if (fieldMap.containsKey(itemId)) {
            Map&lt;Object, Field&gt; fieldMap2 = fieldMap.get(itemId);
            if (fieldMap2.containsKey(propertyId)) {
                return fieldMap2.get(propertyId);
            }
        }
        // Create the field
        ....

In the end of the function I add the fields to the “MapMap”. I added one row to my table and put a breakpoint into the start of function. After I changed a value it caught up in the breakpoint four times (i got four normal columns and one generated) and every time it fetched the Field from the fieldMap.

I just remember that the formfactory is not the only one adding components to the table - the generated column adds labels too. With high hopes I started implementing a similar Map to my generateCell function. No cigar. Updating the labels instead of giving new ones did not help the repaint -problem. I’m starting to get clueless.