• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

addHandler of custom widget not found when included in another widget

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

While learning GWT I wrote a customer widget StateCity (2 drop boxes & button). When it included in TestContainer, widget in a different GWT app (see code below), it gives a compiler error.

If StateCity widget is added to the RootPanel, by commenting lines 1 & 2 and uncommenting other lines, ti works fine.

I wanted to attach the widget (TestGWTWidget.jar) and the app (TestGWTSample.jar), but it won't let me attach.

[DEBUG] [testgwtsample] - Rebinding com.test.sample.client.TestContainer.TestContainerUiBinder
[DEBUG] [testgwtsample] - Invoking generator com.google.gwt.uibinder.rebind.UiBinderGenerator
[ERROR] [testgwtsample] - Field 'stateCity' does not have an 'addStateChange2Handler' method associated.
[ERROR] [testgwtsample] - Deferred binding failed for 'com.test.sample.client.TestContainer.TestContainerUiBinder'; expect subsequent failures
[ERROR] [testgwtsample] - Unable to load module entry point class com.test.sample.client.TestGWTSample (see associated exception for details)
[ERROR] [testgwtsample] - Failed to load module 'testgwtsample' from user agent 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E; MS-RTC LM 8; McAfee)' at 127.0.0.1:60090

public class TestGWTSample implements EntryPoint
{
public void onModuleLoad()
{
1. final TestContainer testC = new TestContainer();
2. RootPanel.get().add(testC);
/*
final StateCity stateCity = new StateCity();
stateCity.setStates(getStates());
stateCity.addStateChange2Handler(new StateChange2Handler() {
public void onStateChange2 (StateChange2Event ev) {
Window.alert("Event");
}
});
RootPanel.get().add(stateCity);
*/
}
}

TestContainer.java
----------------------
public class TestContainer extends Composite
{
private static TestContainerUiBinder uiBinder = GWT.create(TestContainerUiBinder.class);

interface TestContainerUiBinder extends UiBinder<Widget, TestContainer> {}

@UiField StateCity stateCity;

public TestContainer() {
initWidget(uiBinder.createAndBindUi(this));
stateCity.setStates(getStates());
}

@UiHandler("stateCity")
void onStateChange2(StateChange2Event e)
{
if ( e.evType == StateChange2Event.StateCityEventType.StateChanged ) {
stateCity.setCities(getCities(e.newValue));
}
else if ( e.evType == StateChange2Event.StateCityEventType.Done ) {
Window.alert("Done");
}
}

private List<String> getStates ()
{
ArrayList<String> list = new ArrayList<String>();
list.add("... Select a state ...");
list.add("MA");
list.add("NH");
return list;
}

private List<String> getCities (String state)
{
ArrayList<String> list = new ArrayList<String>();
list.add("... Select a city ...");
if ( state.contains("...")) {
}
else if ( state.equals("MA")) {
list.add("Cambridge");
list.add("Boston");
}
else if ( state.equals("NH")) {
list.add("Nashua");
list.add("Salem");
}
return list;
}
}

TestContainer.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"
xmlns:t3="urn:import:com.test3.client">
<ui:style>
.important {
font-weight: bold;
}
</ui:style>
<g:HTMLPanel>
<t3:StateCity ui:field="stateCity" />
</g:HTMLPanel>
</ui:UiBinder>

StateCity.java
----------------
public class StateCity extends Composite implements HasStateChange2Handler
{
private static StateCityUiBinder uiBinder = GWT.create(StateCityUiBinder.class);

interface StateCityUiBinder extends UiBinder<Widget, StateCity> {}

@UiField ListBox stateCB;
@UiField ListBox cityCB;
@UiField Button okB;

public StateCity() {
initWidget(uiBinder.createAndBindUi(this));
}

public StateCity(List<String> states) {
initWidget(uiBinder.createAndBindUi(this));
setStates(states);
}

@Override
public HandlerRegistration addStateChange2Handler(StateChange2Handler handler) {
return addHandler(handler, StateChange2Event.TYPE);
}

@UiHandler ("stateCB")
public void onChange (ChangeEvent event)
{
StateChange2Event ev = new StateChange2Event();
ev.evType = StateCityEventType.StateChanged;
ev.newValue = stateCB.getValue(stateCB.getSelectedIndex());
fireEvent(ev);
}

@UiHandler ("okB")
public void onClick (ClickEvent event)
{
StateChange2Event ev = new StateChange2Event();
ev.evType = StateCityEventType.Done;
fireEvent(ev);
}

public void setStates (List<String> list) {
stateCB.clear();
for ( String s : list ) {
stateCB.addItem(s);
}
}

public void setCities (List<String> list) {
cityCB.clear();
for ( String s : list ) {
cityCB.addItem(s);
}
}

public String getState () { return getSelected (stateCB); }
public String getCity () { return getSelected (cityCB); }

public String getSelected (ListBox listBox)
{
String ret = null;
int ind = listBox.getSelectedIndex();
if ( ind > -1 ) {
listBox.getValue(ind);
}
return ret;
}
}

StateCity.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">
<ui:style>
.important {
font-weight: bold;
}
</ui:style>
<g:HTMLPanel>
<g:VerticalPanel height="80px" width="208px">
<g:HorizontalPanel width="208px" height="25px">
<g:Label text="State: " width="58px"/>
<g:ListBox width="123px" ui:field="stateCB"/>
</g:HorizontalPanel>
<g:HorizontalPanel height="25px" width="208px">
<g:Label text="City: " width="58px"/>
<g:ListBox width="123px" ui:field="cityCB"/>
</g:HorizontalPanel>
<g:Button width="123px" text="OK" ui:field="okB"/>
</g:VerticalPanel>
</g:HTMLPanel>
</ui:UiBinder>
-----------------------------------------------

Any help is greatly appreciated.

Regards,
- Roger
 
Get off me! Here, read this tiny ad:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!