UiBinder and abstract class

643 views
Skip to first unread message

damians

unread,
Feb 1, 2010, 6:22:10 AM2/1/10
to Google Web Toolkit
Hello,

I've got a problem and i googled lots of pages to see if anyone got
the same problem but i didn't find anything.

I've got class AbstractDialog that extends DialogBox with some
standart buttons like OK CANCEL that are bound by UiBinder. I've got
another class that extends AbstractDialog with another declarative xml
file, that contains only the main content of that DialogBox.

When am trying to lunch application i got this error:
Rebinding <package>.<class>UiBinder
Invoking com.google.gwt.dev.javac.StandardGeneratorContext@a51c3c
Method 'ok' can not be bound. You probably missed
ui:field='okButton' in the template.

Method ok and UiHandler for button okVutton is declared in
AbstractDialog. From class that extends AbstractDialog the UiField is
not visible. Am i doing something wrong or i just didnt saw any
information that you can not extends an object tha got his own
UiBinder and extended class got their own UiBinder as well.

My code:

AbstractDialogBox.java

public abstract class AbstractDialogBox extends DialogBox
{
private static AbstractDialogBoxUiBinder uiBinder = GWT.create
(AbstractDialogBoxUiBinder.class);

interface AbstractDialogBoxUiBinder extends UiBinder<Widget,
AbstractDialogBox>
{
}

@UiField Button okButton;
@UiField Button cancelButton;
@UiField Label emptyLabel;
@UiField VerticalPanel main;

public AbstractDialogBox()
{
setWidget(uiBinder.createAndBindUi(this));
setStyleName("oe-DialogBox");

okButton.setText("OK");
cancelButton.setText("CANCEL");
}

public void setContent(Widget content)
{
main.add(content);
}

@UiHandler("okButton")
void ok(ClickEvent e)
{
onOK();
}

@UiHandler("cancelButton")
void cancel(ClickEvent e)
{
onCancel();
}

public void keyPress(KeyPressEvent event)
{
if (event.getCharCode() == 13)
onOK();
else if (event.getCharCode() == 27)
onCancel();
}

public abstract void onOK();
public abstract void onCancel();
}

AbstractDialog.ui.xml

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">

<g:HTMLPanel>
<table width="320px" cellspacing="0" cellpadding="3">
<tr>
<td colspan="3"><g:VerticalPanel ui:field="main" width="100%"/></
td>
</tr>
<tr>
<td><g:Label ui:field="emptyLabel" width="140px"/></td>
<td><g:Button ui:field="okButton" styleName="dialogButton"/></td>
<td><g:Button ui:field="cancelButton" styleName="dialogButton"/></
td>
</tr>
</table>
</g:HTMLPanel>
</ui:UiBinder>

LoginOptionDialog.java that extends AbstractDialog

public class LoginOptionDialog extends AbstractDialogBox
{
private static LoginOptionDialogUiBinder uiBinder = GWT.create
(LoginOptionDialogUiBinder.class);
interface LoginOptionDialogUiBinder extends UiBinder<Widget,
LoginOptionDialog> {}

@UiField Image icon;
@UiField Label descIp;
@UiField TextBox ip;
@UiField HTMLPanel content;

public LoginOptionDialog()
{
super();

setText("Login options");

descIp.setText("Server IP:");
ip.setText("Enter ip");

setContent(content);
}

@UiHandler("ip")
public void press(KeyPressEvent event)
{
keyPress(event);
}

public void onCancel()
{
// restore ip text from application context
hide();
}

public void onOK()
{
// set ip in application context
hide();
}
}

LoginOptionDialog.ui.xml

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">

<g:HTMLPanel ui:field="content">
<table width="100%" cellspacing="0" cellpadding="3">
<tr>
<td><g:Image ui:field="icon" url="gfx/ServerIp.png" width="23px"
height="23px"/></td>
<td align="center"><g:Label ui:field="descIp"
styleName="dialogText" wordWrap="false" width="126px"/></td>
<td><g:TextBox ui:field="ip" styleName="dialogText" width="165px"/
></td>
</tr>
</table>
</g:HTMLPanel>

</ui:UiBinder>


Enviroment that am using to launch it:

public class Application implement EntryPoint
{
private LoginOptionDialog loginOptionDialog;
private Button optionButton;

public void onModuleLoad()
{
optionButton = new Button("Options");
optionButton.addClickHandler(new ClickHandler()
{
public void onClick(ClickEvent event)
{
loginOptionDialog.setPopupPosition(optionButton.getAbsoluteLeft()
- 100,

optionButton.getAbsoluteTop() - 60);

loginOptionDialog.show();
}
});
loginOptionDialog = new LoginOptionDialog();

RootPanel.get("optionButton").add(optionButton);
}
}

matttai

unread,
Feb 1, 2010, 6:25:17 PM2/1/10
to Google Web Toolkit
You are probably setting setWidget(uiBinder.createAndBindUi(this)); in
the extended class. I don't see your bind statement for the second
class so i cannot tell so it is just a guess.

Bind the loginbox content for the LoginDialogBox as a widget and pass
it in for your bind in the setContent(content); statement

Luis Costa

unread,
Mar 21, 2012, 7:13:01 AM3/21/12
to google-we...@googlegroups.com
Hello all,
I'm having the same doubt, 
Damians, did you put your code working?
I'm having the same error.
Thanks,
Luis.

Thomas Broyer

unread,
Feb 8, 2013, 11:09:12 AM2/8/13
to google-we...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages