Saturday, December 19, 2009

Adsense Ads and GWT - Making it work.

It seems like a lot of people have had this same problem, but I haven't found anywhere on the net where someone has found a solution. Here's how I got it to work. If you find this post helpful, I would ask the favor that you check out http://penwag.com, and ask your friends to do the same.

I struggled for a long time trying to get an Adsense ad to appear in a <div>, but that seems to be the wrong approach. Divs are nice for styling reasons, but it seems that Adsense knows when it's in a div, and won't display.

I avoided IFrames (which is what the GWT Frame object compiles to) because sizing isn't automatic. Eventually, though, it became apparent that IFrames were the way to go, since Adsense ads will load in them. I create an IFrame and point it at a static page that contains the necessary Adsense script. That just works. The content loads correctly, and ads will display.

But here's the rub. IFrames need to be sized with custom javascript. I use this javascript: https://penwag.com/home/iframe.js. This works easily for all browsers except - you guessed it - IE. Below is the GWT code that I use to bring it all together, including a work-around for IE.


public static native String getUserAgent() /*-{
return navigator.userAgent.toLowerCase();
}-*/;

private Widget buildMainPanel() {
Widget mainPanel;
if(getUserAgent().contains("msie")) {
mainPanel = buildIEPanel();
} else {
mainPanel = buildNonIEPanel();
}

mainPanel.getElement().setId(getPanelId());
mainPanel.addStyleName(Styles.StaticPanel);

return mainPanel;
}

private Widget buildNonIEPanel() {
Frame mainPanel = new Frame();
mainPanel.getElement().setAttribute("onLoad", "resizeCaller();");
mainPanel.setUrl(getRootPage());

return mainPanel;
}

private Panel buildIEPanel() {
Panel mainPanel = new VerticalPanel();

HTML adBar = new HTML("Loading...");
mainPanel.add(adBar);

try {
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, GWT.getModuleBaseURL() + "ie_ads/index.html");
builder.sendRequest(null, new RequestHandler(adBar, null));
} catch (RequestException e) {
adBar.setHTML("");
}

HTML content = new HTML("Loading...");
mainPanel.add(content);

String errorMessage = "Failed to load content, please try again later.";
try {
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, GWT.getModuleBaseURL() + getRootPage());
builder.sendRequest(null, new RequestHandler(content, errorMessage));
} catch (RequestException e) {
content.setHTML(errorMessage);
}

return mainPanel;
}

Saturday, November 14, 2009

New Feature - Updated Layout

Today's new feature is really a few new features. The layout's completely revised to allow for better growth and a broader, richer experience for visitors that are interested to share stories and grow as writers. As the new layout is filled in, writers, storytellers, student, and poets should expect to have a place on the web where they can try their craft in front of an audience, and have many of the tools and resources they need to grow as writers.

Saturday, October 31, 2009

New Feature - Author Contact

Actually, there have been quite a few changes since the last post, mostly in the area of infrastructure changes. I switched the VPS from RapidVPS to Linode. Also in there somewhere I switched over from two old-school engines (Tomcat and Apache) to more advanced solutions (Jetty and Nginx) that support a leaner, meaner application, which in the end means a better user experience.

The new feature for today is Author Contact. Authors can now be available for contact to editors, readers, and anyone else that might want to make contact. Authors control this setting through their Profile. Author's emails are kept private. This option is turned off by default. If you want to be contacted, you have to log in and turn it on.

For readers, this means that you can now contact your favorite authors, and ask for more great stories, poems, whatever. Editors/publishers can browse the site, and contact promising authors.

Authors that are available for contact will have a little envelope next to their name in the story lists. Readers of stories will see a "Contact Author" button while they're viewing the story. The reader's email and message will be sent to the author, allowing them to reply directly to the reader.

Saturday, October 24, 2009

A New Star

I'd like to introduce you all to an up-and-coming star in the universe of photography. Also, he's my son, Taylor. I may be biased.

Please take a moment to visit his web site PhotoImageOgraphy. I think you'll be glad you did.

Sunday, September 27, 2009

New Features

Per Karen's excellent suggestion, you no longer have to be a registered user to explore the features of PenWag. There's now a visitor's mode that lets visitors read stories and generally explore the site before they commit to registering.

Other recent features:
- Switch from recover password to reset password for enhanced security.
- Passwords on now hashed and not stored in the clear (!), again, for enhanced security.
- Upgraded to GWT 1.7, which allowed me to get the story list grid styled correctly.
- The Teasers are now cached using ehCache, which improves performance across-the-board.

Friday, July 3, 2009

PenWag In The GWT Gallery

PenWag is now in the GWT application gallery. Does that make it official now? Whatever "it" is?

Thursday, June 25, 2009

New Look And Better Performance

I just pushed out a new version of PenWag last night with a new look. No sweeping changes, but wanted to get rid of the old-style navigation and clean some things up.

I also spent some time on rebuilding and tuning the reverse proxy for better memory usage (since the VPS max mem is 128M) and better connection handling. The performance is definitely much better now.

Tuesday, June 9, 2009

Teasers - Back To Adding Features

Well, now that the 1.5 to 1.6 upgrade is (mostly) behind me, it's back to adding features.

I've been meaning to get around to turning the story viewer into a scrollable pane. That was just changes to a line or two of code, so that's deployed to penwag.com.

Also, I've been talking to my son Taylor off and on about how to promote the site. He suggested adding a teaser to the main page, that people see part of a story, and can get a taste of what's inside. Perhaps they'll read the intro to a story, and be hooked enough to register and read the rest. Now that's built and deployed. Each time a user visits the site, it randomly picks from one of the stories I've marked as a candidate.

If you haven't come out to the site yet, have a look. It's in its infancy now, come and watch it grow!

Tuesday, June 2, 2009

Upgrade from GWT 1.5 to GWT 1.6 - Again

Well, I wasn't satisfied with the result of the upgrade. Although sometimes I like to try the same thing again and see if the the outcome is different, this time I tried a different approach to see if the outcome was different.

The problem with a straightforward upgrade was the "danglers" from the 1.5 directory structure. During the conversion, it was hard to tell what could be thrown away and what needed to be kept without going through everything carefully.

So, I decided to created a new project, using the current tools, let it build exactly the directory structure it wants, then copy stuff in until it works. Basically. There was some moving around, there were changes to build.xml, and miscellaneous cleanup. But, all my UTs passed, all my ATs passed, and it's good to go.

I still need to swap out what's deprecated in the API for what's current, but that can happen later.

Also in the process, I switched repositories from Subversion to Git. Git takes us back to the command-line world that we had years back with CVS, but it's far-and-away better than the other repo options out there: Local branching, rebase, gitk, bisect, workflow smorgasbord, and more. Very nice. By following this workflow I can auto-collaborate and work on the same branch on my desktop or at the local Breadco.

Monday, May 4, 2009

Upgrade from GWT 1.5 to GWT 1.6

I finished the upgrade of PenWag from GWT 1.5 to 1.6, following the instructions here. It was kind of a pain, really. It requires a little jumping through hoops that the instructions don't cover, so I attempted to capture them all on Stack Overflow.

Friday, April 17, 2009

April Update

Not much to report really. Fixed a few bugs and made some updates that are not visible to the user. Did add a story to the site talking about the bat in the house, which was quite an interesting experience. I think the next development story to complete is to put the story viewer in a scrollable pane of some kind. Right now, long stories just bleed off the bottom of the viewer. They're readable, it's just not pretty.

Sunday, March 29, 2009

New Feature - Edit Story

PenWag now allows authors to modify existing stories. Now, this is a pretty essential feature for PenWag. Previously, authors had the ability to write new stories, but couldn't go back and make corrections. It's basic enough that I had mixed feelings about going public without it. Nevertheless, now it's there.

In order to change a story you've written, click on a story from "My Stories," then click "Edit." You'll be taken back to the Write tab, and you can change the title, the genre, and the contents of the story.

Enjoy!

If you haven't registered yet, I encourage you to register today. It's very straightforward. Click on the "Register" button, and follow the process. Please let me know if the process is unclear. I already have a couple stories out there, and I'll be adding more as I remember them.

Saturday, March 28, 2009

Tell Your Story!

There's a web site that I'm building, penwag.com, that lets me enjoy two of my favorite interests: software development and story telling.

It lets me enjoy software development
in that I'm using two technologies that I will gain experience with: the Google Web Toolkit (GWT) and Hibernate. The GWT is a great tool from Google that provides a framework for building AJAX-style applications. The framework includes the necessary pieces for client-side and server-side development, and manages the communication between the layers. Add in Hibernate and a data layer, and you have everything you need for easily building AJAX web sites.

Then there's the story-telling side.
When I was very little, we visited my great-uncle Henry Shoop, who was my father's mother's brother. He was born near Cherryville, Missouri, but his family moved to California when he was six. Uncle Henry was a friend, a beekeeper, and one of the great storytellers, and I hung on his every word as he instilled in me a love for a well-told story. He was one of the best.

Another favorite story-teller of mine was Earl Halbert, a family friend. You can see his picture here from National Geographic Magazine. He's the one on the left in the overalls. Earl was born in 1910 in rural Missouri, and lived through the Great Depression, Prohibition and numerous other hard times. He knew my great-grandfather Thomas Jefferson Branson, and had a few good stories to share about him as well.

Both of these men, shall we say, infected me with a love of a story told friend-to-friend, perhaps while sipping some sassafras tea, or around a campfire, or just hanging out in the living room. I miss both of them not just for their story-telling and their wit, but for their character as human beings.

Certainly the art of a well-told story has not been lost, but is changing over time. How many people nowadays have had the chance to hear stories of hard times in the Great Depression, friends lost, good times, and funny times, from "way back when"? I'd hate to lose those stories. So join me, won't you, and let's tell each other those stories, like we're sitting over a beer or around a campfire, and let's enjoy a good laugh together, savor tales of clever dealings with shysters, and the occasional twist ending.

Just head out to penwag.com. You're getting in early at a site that will someday, hopefully, have many stories that we have shared with each other. But it's your stories that will make the site great. If you have even one story to share, come on out and put it up there.

This site is in its early stages, but everything you need to add a story and read others' stories is already there. Since it's in its early stages, there's still a lot of work that I need to do add features. Some are pretty obvious - you can create a story, but can't edit the story to make corrections yet. I have a long list of features that I will add as the site grows. But the feature you want may not be on my list! So, click on the Contact Support link, or just send an email to support@penwag.com, and give me a shout. Tell me what feature you want, and I'll add it to my list.

Let me reiterate - this site's success depends on people like you who have a story to tell. As you add your stories, others will visit the site just to read a great story. The stories are short. Don't feel like you have to write a novel. Just write it how you would share it with your friends over a beer.

Now, to get started, you have to register. For simplicity's sake, your email address is your user id, and you need to make up a password. Registration is quick and easy, and your email address will not be shared. If you still have questions or concerns, or if the site doesn't work right for you, use the Contact Support link and let me know!

Thanks, and hope to see you out there. Come tell your story!