Custom ValueBoxEditorDecorator

255 views
Skip to first unread message

abby

unread,
May 5, 2011, 11:58:08 AM5/5/11
to Google Web Toolkit
Any pointers on creating a custom valuebox editor decorator? What is
the easiest approach? It seems simply replacing the decorator won't
work as it is tied at the hip all the way to Valuebox. Any suggestions
are appreciated?

Thomas Broyer

unread,
May 5, 2011, 12:15:44 PM5/5/11
to google-we...@googlegroups.com
Assuming you want to replicate the HasEditorErrors behavior (otherwise, I don't see the point in having the decorator an Editor by itself), it'll depends whether you want to decorate a LeafValueEditor or an Editor with sub-editors, and/or an IsEditor.
We learned it the hard way this week, so better share our findings than let you drive nuts with something that works in some cases and not in others.

For a LeafValueEditor, make your decorator an IsEditor and HasEditorErrors, with the asEditor() method returning your wrapped LeafValueEditor. For an IsEditor<LeafValueEditor<?>>, you'd have to "unwrap" it (call asEditor) yourself (like ValueBoxEditorDecorator does), which presumes the editor isn't itself both an IsEditor and an Editor (HasEditorDelegate, HasEditorErrors, etc.). Being both IsEditor and Editor is IMO a bad practice, but sometimes you don't have the choice.

For a complex Editor (with sub-editors), do not implement IsEditor, but instead use a @Path("") sub-editor (typed either as your Editor type or IsEditor depending on what you need).

For the rest, you can basically copy from ValueBoxEditorDecorator.

HTH, ask if you need more info.

Thomas Broyer

unread,
Jan 24, 2013, 4:47:47 AM1/24/13
to google-we...@googlegroups.com


On Wednesday, January 23, 2013 8:50:17 PM UTC+1, Joe Bandenburg wrote:
I'm trying to create a decorator that works for LeafValueEditor as opposed to ValueBoxEditor but I'm finding that, in the case of ValueBoxEditor showErrors is passed two EditorError objects per error. One that has an editor that equals the ValueBoxEditor and the other that has an editor that equals the decorator. If all I change is the type of editor returned from asEditor to LeafValueEditor, then only one EditorError is passed in, with an editor equal to the decorator. What's going on here?

It might be because ValueBoxEditor is a HasEditorDelegate. Anyway, that's a bug. We have a patched ErrorCollector in a project, but unfortunately we didn't document what the bugs were that lead us to patch it, but it had to do with errors "bubbling up" the editor hierarchy and/or aliased editors (several editors for the same path, as is the case for ValueBoxEditorDecorator); I'm really not sure our changes are the "correct" ones either, all I can say is that they "work for us". So any test-case is welcome!
Reply all
Reply to author
Forward
0 new messages