Overlay types in cell widgets

Showing 1-7 of 7 messages
Overlay types in cell widgets Javier 1/19/11 3:37 PM
Hi,

My app is using overlay types with JSON received from server. In the
view I'm pushing the list of overlay types into a cell table:

public class JsTask extends JavaScriptObject {}

taskTable = new CellTable<JsTask>();
taskTable.setRowData(0, tasks);

For my surprise I have found that the widget is adding an extra
property to the JavaScriptObject containing it's row index in the
table. So, my overlay type that looked like this:

{"_id":"4039344d00005fd600000017", "title":"Nuevo titulillo",
"version":0}

Now looks:

{"_id":"4039344d00005fd600000017", "title":"Nuevo titulillo",
"version":0, "$H":6}

I don't think this is a nice behaviour. In my particular case the
overlay is a domain object so it should not have unexpected
properties.

Is this behaviour documented somewhere? What do you think is the best
way to solve this issue? Am I forced to "clone" all my domain objects
before using them in my views?

Many thanks
Re: Overlay types in cell widgets John LaBanca 1/19/11 7:35 PM
CellTable doesn't modify the original data, so this is either related to RPC or to our List implementation.

Thanks,
John LaBanca
jlab...@google.com


On Wed, Jan 19, 2011 at 6:37 PM, Javier <javierf...@gmail.com> wrote:
Hi,

My app is using overlay types with JSON received from server. In the
view I'm pushing the list of overlay types into a cell table:
How do you get them from the server?  RPC, RequestFactory, or JsonRequest?

public class JsTask extends JavaScriptObject {}

taskTable = new CellTable<JsTask>();
taskTable.setRowData(0, tasks);

For my surprise I have found that the widget is adding an extra
property to the JavaScriptObject containing it's row index in the
table. So, my overlay type that looked like this:

{"_id":"4039344d00005fd600000017", "title":"Nuevo titulillo",
"version":0}
Does it look like this on the server or on the client after the request from the server?   

Now looks:

{"_id":"4039344d00005fd600000017", "title":"Nuevo titulillo",
"version":0, "$H":6}

I don't think this is a nice behaviour. In my particular case the
overlay is a domain object so it should not have unexpected
properties.

Is this behaviour documented somewhere? What do you think is the best
way to solve this issue? Am I forced to "clone" all my domain objects
before using them in my views?

Many thanks

--
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-we...@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.


Re: Overlay types in cell widgets Javier 1/20/11 2:25 AM
Thanks for answering John,

I use JsonRequest to get the data from the server and store it in a
List.

I'm pretty sure the data is modified in the cell table. In this code
from my view I print the data before and after pushing it into de cell
table:

        @UiField(provided = true)
        CellTable<JsTask> taskTable;

        public void setTasks(List<JsTask> tasks) {
                printTasks("BEFORE", tasks);
                taskTable.setRowData(0, tasks);
                printTasks("AFTER", tasks);
        }

        private void printTasks(String key, List<JsTask> tasks) {
                for(JsTask task : tasks) {
                        GWT.log(key + ": " + new JSONObject(task).toString());
                }
        }

And the output is:

11:10:51.658 [INFO] [noah] BEFORE: {"_id":"c109384d00005fd600000017",
"title":"This is a task", "version":0}
11:10:51.667 [INFO] [noah] BEFORE: {"_id":"c009384d00005fd600000017",
"title":"This is another task", "version":0}
11:10:51.689 [INFO] [noah] AFTER: {"_id":"c109384d00005fd600000017",
"title":"This is a task", "version":0, "$H":1}
11:10:51.696 [INFO] [noah] AFTER: {"_id":"c009384d00005fd600000017",
"title":"This is another task", "version":0, "$H":2}

where the widget is adding those $H properties.

On 20 ene, 04:35, John LaBanca <jlaba...@google.com> wrote:
> CellTable doesn't modify the original data, so this is either related to RPC
> or to our List implementation.
>
> Thanks,
> John LaBanca
> jlaba...@google.com
> > google-web-toolkit+unsubscribe@googlegroups.com<google-web-toolkit%2Bunsubscribe@googlegroups.com>
> > .
Re: Overlay types in cell widgets Javier 1/20/11 3:45 PM
I have checked that the issue happens when you add a custom column to
the table. For instance:

// Create name column.
        Column<Contact, String> nameColumn = new Column<Contact,
String>(new EditTextCell()) {
            public String getValue(Contact object) {
                return object.getName();
            }
        };

More details here: http://stackoverflow.com/questions/4753898/gwt-cell-widgets-with-overlay-types-issues
Re: Overlay types in cell widgets Thomas Broyer 1/21/11 2:18 AM
The $H property comes from the implementation of JavaScriptObject#hashCode() (in com.google.gwt.cire.client.impl.Impl#getHashCode(Object)).

In your case, this is due to AbstractEditableCell maintaining a map of value keys to their "view data", and your use (I guess) of the default ProvidesKey implementation (SimpleProvidesKey) which directly returns the item.

So, when rendering, the EditTextCell calls getViewData, which looks up the key in the map (and thus needs the hashcode of the key, hence the call to hashCode), and the key is your JSO (hence the new $H property).

I believe that giving a ProvidesKey implementation (in you case, returning the name property for instance) to the Celltable would solve your issue.
Re: Overlay types in cell widgets Javier 1/21/11 5:40 AM

You are right! Giving a ProvidesKey solves the issue. For next
releases it would be great if overlay types could define their own
hashCode.

Thanks a lot, not only for the solution but also for the detailled
explanation.
Re: Overlay types in cell widgets Eugen Paraschiv 6/3/11 5:12 AM
Hi, I have the exact same problem, but using a ProvidesKey doesn't seem to change anything; this is my exact context:

- I have a custom column for a button:

return new Column<Customer, String>(new ButtonCell()) {
            @Override
            public final String getValue(@SuppressWarnings("unused") final Customer object) {
                return "Action";
            }

            @Override
            public final void onBrowserEvent(final Cell.Context context, final Element elem, final Customer customer,
                    final NativeEvent event) {
                if (event.getButton() == NativeEvent.BUTTON_LEFT) {
                    selectedCustomer = customer;
                    createPopupActionMenu(event.getClientX(), event.getClientY());
                }
            }

and a selection model:

        final SingleSelectionModel<Customer> selectionModel = new SingleSelectionModel<Customer>(keyProvider);
        customersTable.setSelectionModel(selectionModel);

I have now given both this selection model and the actual table, a ProvidesKey object:

        final ProvidesKey<Customer> keyProvider = new ProvidesKey<Customer>() {
            @Override
            public final Object getKey(final Customer customer) {
                return customer.getId();
            }
        };

        customersTable = new CellTable<Customer>(keyProvider);
        final SingleSelectionModel<Customer> selectionModel = new SingleSelectionModel<Customer>(keyProvider);

When I do: new JSONObject(editedCustomer).toString()
I'm still getting the: "$H":1
in the output json.
Any idea why this would be?

Thanks, any help on this is appreciated.
Eugen.