TurboManage

David Chandler's Journal of Java Web and Mobile Development

  • David M. Chandler


    Web app developer since 1994 and Google Cloud Platform Instructor now residing in Colorado. Besides tech, I enjoy landscape photography and share my work at ColoradoPhoto.gallery.

  • Subscribe

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 228 other followers

  • Sleepless Nights…

    September 2009
    S M T W T F S
     12345
    6789101112
    13141516171819
    20212223242526
    27282930  
  • Blog Stats

    • 1,010,175 hits

Archive for September, 2009

OK, what I don’t like about GWT

Posted by David Chandler on September 28, 2009

I spent all day adding a single button. I wanted an icon and text in the button. The standard GWT buttons let you do text or image, but not both. I didn’t want to bring in a 3rd party library like ext-gwt just for that. So I messed with FlexTables and FlowPanels and CSS all day. Along the way, I learned to prefer FlexTables over HorizontalPanels and VerticalPanels because with a FlexTable you can easily set the style for a given cell like this:

bodyPanel.getCellFormatter().addStyleName(0,1,"myStyleName");

With the other types of panels, you can set a style for the whole panel or a nested widget; however, things like float and width don’t seem to get picked up as well as they do using the FlexTable method.

On a related note, I had issues with text bleeding outside my PushButton when I wrapped it with a HorizontalPanel. But when I wrapped it with a FlowPanel, it worked fine. So I’ll try to use Flex and Flow panels primarily from now on.

I did find a way to create a PushButton containing an image and a label. Here’s the basic idea:

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PushButton;

public class PrettyButton extends Composite
{
	public PrettyButton(Image image, String buttonText)
	{
		FlowPanel fPanel = new FlowPanel();
		fPanel.add(image);
		fPanel.add(new Label(buttonText));
		PushButton button = new PushButton();
		button.setHTML(fPanel.getElement().getInnerHTML());
		this.initWidget(button);
	}
}

I’m learning to call addStyleName() on every widget I create. Been a while since I’ve been heavy into CSS, but I feel a refresher coming on…

Posted in Google Web Toolkit | 2 Comments »

More Benefits of gwt-dispatch

Posted by David Chandler on September 25, 2009

When you use gwt-dispatch, a single dispatch servlet handles all service requests, so you no longer need to configure individual servlets in web.xml. Furthermore, action handlers are configured in Java code, like this:

		bindHandler(FindPrayerListsAction.class, FindListsHandler.class);
		bindHandler(AddPrayerListAction.class, AddPrayerListHandler.class);
		bindHandler(DeletePrayerListsAction.class, DeletePrayerListsHandler.class);

Because all configuration is done in Java, you can rename any handler, Action, Result, etc., and the Eclipse refactoring tools automatically rename it everywhere.

And speaking of Eclipse, did you know you can type only the capital letters of a class name and hit Ctrl+Space to let Eclipse automatically expand it? For example, to type “FindPrayerListsAction” above, I could simply type “FPLA” and hit Ctrl+Space. This also works in the Open Type (Ctrl+Shift+T) and Open Resource (Ctrl+Shift+R) dialogs.

Posted in Eclipse, Google Web Toolkit, Model-View-Presenter | Leave a Comment »

GWT + MVP = Very Manageable Code

Posted by David Chandler on September 24, 2009

I’ve been struggling with GWT a bit. It’s a new way of thinking for someone who’s been writing Web apps on the server side for 15 years now. But I was intrigued by a few posts on GWT with MVP, and then I found this:

http://blog.hivedevelopment.co.uk/2009/08/google-web-toolkit-gwt-mvp-example.html

I cannot say it or do it any better. It took me about a day to rewire my small GWT + AppEngine app with gwt-presenter and gwt-dispatch. It worked the first time. Color me impressed.

I can understand my own GWT code far more easily now.

And it’s more testable.

And more modular so other developers can work on it at the same time.

Did I mention I was impressed?

For the CM-inclined, these are the jar versions I put in my GWT project’s lib directory:

  • gwt-dispatch-1.0.0.jar from the project’s Downloads page
  • gwt-presenter-1.0.0.jar from the project’s Downloads page
  • gin.jar from GIN project’s out/dist folder I built from SVN trunk on 9/23/09
  • guice-2.0.jar from GIN’s lib folder per the blog post above

Posted in GIN / Guice, Google Web Toolkit, Model-View-Presenter | 4 Comments »

Getting Started with GIN and Guice

Posted by David Chandler on September 23, 2009

As part of the RememberOneAnother project, I’m using the excellent gwt-presenter and gwt-dispatch frameworks, which in turn depend on GIN and Guice. You can download the Guice jars from the project site, but you have to build GIN. I did the following in Eclipse:

  1. Set a GWT_HOME env variable to C:\eclipse\plugins\com.google.gwt.eclipse.sdkbundle.win32_1.7.0.v200907291526\gwt-windows-1.7.0 and restart Eclipse to pick up the new var.
  2. Download Guice.
  3. Check out GIN from SVN (see the project Source tab for location) as a new Java project using the New Project Wizard.
  4. Add the guice-2.0.jar to the GIN project’s build path.
  5. Right-click on the GIN build.xml and click Run As Ant Build… In the Targets tab, select the “dist” target. In the JRE tab, make sure a JDK is specified and not just a JRE.
  6. Click Run to build GIN. The resulting gin.jar will be put in the out/dist folder. You may need to unfilter .* resources to see it.

Posted in GIN / Guice, Google Web Toolkit | Leave a Comment »

Method #37 to write an infinite loop

Posted by David Chandler on September 21, 2009

I’ve always thought, had I been keeping track, that it would have been fun to write a book entitled 101 Ways to Write an Infiinite Loop. It seems in every new language or framework I’ve learned, I’ve soon found a way to do it. My latest method involves event handlers in Google Web Toolkit, which I’ve adopted for the RememberOneAnother project.

	public void actionFindLists()
	{
		GWT.log("Calling actionFindLists", null);
		svc.getLists(new AsyncCallback<java.util.List<List>>()
		{
	
			@Override
			public void onFailure(Throwable caught)
			{
				Window.alert(caught.getLocalizedMessage());
			}
	
			@Override
			public void onSuccess(java.util.List<List> result)
			{	
				// setPrayerLists(result);
				eventBus.fireEvent(new NewListEvent());
			}
		});
	}


	public java.util.List<List> getPrayerLists()
	{
		if (prayerLists == null)
			actionFindLists();
		return prayerLists;
	}

The getPrayerLists() method above uses lazy initialization on the prayerLists field to invoke a GWT-RPC service when the view first loads. Without the line that’s commented out, however, the prayerLists field never takes on a non-null value, which causes the service to be called ad infinitum. Moral of the story: when using lazy initialization, don’t forget to initialize the property somewhere!

Posted in Google Web Toolkit | Comments Off on Method #37 to write an infinite loop

 
%d bloggers like this: