I come from a background of C#; I'm trying to adjust to working with
GWT and AppEngine, but as you all know the approach to developing a
GWT application is very different. I'm especially having difficulty
with the client-side organization of code, which is made even more
difficult due to my relative ignorance of the object model as a whole.
The examples I've seen of "EntryPoint" objects and their
"onModuleLoad" method have all the event handlers and the actual
handling delegates within the scope of "onModuleLoad" and the widgets
that it created. I'd like to be able to encapsulate a handler in a
separate class and access the widgets from within it.
For example my code currently looks something like this:
// entry point
public void onModuleLoad()
{
//
txtName.setName( "txtName" );
txtName.setText( "GWT User" );
txtAddress.setName( "txtName" );
txtAddress.addStyleName( "sendButton" );
//
RootPanel.get( "txtNameOwner" ).add( txtName );
RootPanel.get( "btnSendOwner" ).add( btnSend );
RootPanel.get( "txtAddressOwner" ).add( txtAddress );
// Add a handler to send the name to the server
btnSend.addClickHandler( new ClickHandler(){
public void onClick( ClickEvent event )
{
service.insert( txtName.getText(), txtAddress.getText(),
new AsyncCallback<String>()
{
public void onFailure(
Throwable caught )
{
txtAddress.setText(
caught.getMessage() );
}
public void onSuccess( String
result )
{
txtAddress.setText(
result );
}
} );
}
} );
}
The code isn't very useful I know; I'm just trying to get the
communication between client and server down here. However, what I'd
like to be able to do is something like this:
// entry point
public void onModuleLoad()
{
//
txtName.setName( "txtName" );
txtName.setText( "GWT User" );
txtAddress.setName( "txtName" );
txtAddress.addStyleName( "sendButton" );
//
RootPanel.get( "txtNameOwner" ).add( txtName );
RootPanel.get( "btnSendOwner" ).add( btnSend );
RootPanel.get( "txtAddressOwner" ).add( txtAddress );
// Add a handler to send the name to the server
btnSend.addClickHandler( new MyCustomHandler() );
}
public class MyCustomHandler implements ClickHandler, KeyUpHandler
{
public void onClick( ClickEvent event )
{
this.execute( event );
}
public void onKeyUp( KeyEvent event )
{
this.execute( event );
}
private void execute( Event event )
{
/*****************************************/
GET MY WIDGETS SOMEHOW
/*****************************************/
service.insert( txtName.getText(), txtAddress.getText(),
new AsyncCallback<String>()
{
public void onFailure( Throwable caught )
{
txtAddress.setText( caught.getMessage()
);
}
public void onSuccess( String result )
{
txtAddress.setText( result );
}
} );
}
}
Some of the signatures may be wrong, but the essence is there. Could
anyone help me out???
Thanks,
-CHRIS
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---