Custom UIBinder Widget, problem expecting only widgets

1,630 views
Skip to first unread message

John Gentilin

unread,
Oct 9, 2011, 9:10:38 PM10/9/11
to Google Web Toolkit
I am trying to create a custom to use in my UIBinder templates, UL/LI
elements are curiously missing..
I used HTMLPanel as a template where I copied the class source to my
project. The object itself
works fine, but as soon as I try to include HTML code in the element,
the UIBinder parser complains
saying that my UL widget is only expecting Widgets, but the HTMLPanel
can include both HTML and
Widgets.. What am I doing wrong ?

Thanks
-John G

Sudhakar Abraham

unread,
Oct 10, 2011, 3:14:20 AM10/10/11
to Google Web Toolkit
There are two ways to add html tag inside the HTMLPanel. You can add
Unorder List / ListItem (UL/LI) directly to HTMLPanel, or using HTML
class inside the HTMLPanel. Try the below code.

//.xml file
<?xml version="1.0" encoding="UTF-8"?>
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'>
<g:DockLayoutPanel unit='EM'>
<g:west size='10'>
<g:HTMLPanel>
<g:HTML>
<ul>
<li>ListItem</li>
<li>ListItem1</li>
<li>ListItem2</li>
</ul>
</g:HTML>
</g:HTMLPanel>
</g:west>
</g:DockLayoutPanel>
</ui:UiBinder>

//.java
public class HtmlTest extends Composite
{
interface Binder extends UiBinder<Widget, HtmlTest>{}
Binder binder = GWT.create(Binder.class);

public HtmlTest()
{
initWidget(binder.createAndBindUi(this));
}

}

S. Abraham
www.DataStoreGwt.com
Persist objects directly in GAE

John Gentilin

unread,
Oct 10, 2011, 4:47:15 AM10/10/11
to google-we...@googlegroups.com, Sudhakar Abraham
What I am trying to do is set up a blank UL container I can fill from my
control code..
ie. below, where UnorderedList is a Java class that I used the source
from HTMLPanel
as a starting point..

<?xml version="1.0" encoding="UTF-8"?>
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'

xmlns:MyWidget='urn:import:com.mypackage.ui'>
<g:HTMLPanel>
<MyWidget:UnorderedList ui:field="galleryContainer"/>
</g:HTMLPanel>
</ui:UiBinder>

The above works fine, and I can access the galleryContainer object as a UIField in my control code..
but if I want to add some static list elements, mostly to see how they look in GWTDesigner, it fails..
i.e.

<?xml version="1.0" encoding="UTF-8"?>
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'

xmlns:MyWidget='urn:import:com.mypackage.ui'>
<g:HTMLPanel>

<MyWidget:UnorderedList ui:field="galleryContainer">
<li><img href="somepic.jpg"/></li>
</MyWidget:UnorderedList>

</g:HTMLPanel>
</ui:UiBinder>

When I go to open GWTDesigner, it fails initialization saying the element MyWidget:UnorderedList
is only expecting Widgets. I pulled in the source for HTMLPanel into my UnorderedList class in its
entirety and only modified it to produce UL elements instead of Div elements.

Not sure what's going on here, I get the feeling that there is some description file somewhere
telling which UI elements are allowed to contain HTML vs Widgets somewhere since the code is
the same as HTMLPanel.

-John Gentilin

Tomasz Gawel

unread,
Oct 10, 2011, 1:48:38 PM10/10/11
to Google Web Toolkit
hi,
as far as gwt 2.1. HTMLPanel was treated somohow special by uibinder.
(i'm not sure if it hasn't changed in newer versions)
normally a widget in ui binder could contain text or html when
implemented hasText and hasHTML interfaces. then the content of the
node in ui.xml was parsed as text or html. however it was not allowed
to contain subwidgets. on the other hand side if a widget implemented
hasWidgets interface (so it was a panel :)) it contents in ui.xml has
been parsed as widgets to be added to that panel.
but HTMLPanel had its own dedicated parser in uibinder:
com.google.gwt.uibinder.elementparsers.HTMLPanelParser, which was
aware of how to parse both widgets-markup and plain-html. but widgets
which inherited from HTMLParser has not been handled by that parser.

but coming back to your particular example :) - if yuo only need a
html markup (not widgets) inside your widget, do not inherit from
HTMLPanel but use HTML widget instead, or Composite and implement
hasHTML.
Reply all
Reply to author
Forward
0 new messages