Site Maintenance

Sorry for the extended downtime. I was performing an upgrade to the fresh and minty Subtext 2.0 which ran into a few issues. Things are better now, so thanks for Phil and crew for making some great (if hard to install) software!

The Perfect Work Week

The family and I just got back from North East, MD visiting family. So Monday was traveling, I took off Tuesday to recuperate (yes, a vacation from my vacation) and Wednesday was our new work from home day. I go into the office tomorrow, but of course Friday is the 4th of July holiday.

Or as I like to call it, the perfect work week.

No Java Here

Turns out we lost the Java job we were looking forward too, bummer. I guess we won't all be Java developers quite yet.

Java IDE's

Being new to the Java scene, one of the first tasks in picking up Java is determining an IDE to use. The main contenders seem to be Eclipse, Netbeans, and IntelliJ IDEA. I cannot say one is universally better than another, but when trying to evaluate them for our needs a few things stuck out.

Eclipse

Pros

  • Can do anything, be anything with the proper plugins.
  • Free

Cons

  • Everything requires a plugin, all of which have differing levels of quality, stability, and usability.
  • Not all plugins are free.

Netbeans

Pros

  • Best out-of-the-box experience.
  • Most "VisualStudio-Like".
  • Visual Designer tools for JSF.

Cons

  • Not quite as well supported in the community (not as many plugins).

IntelliJ IDEA

Pros

  • Powerful refactoring tools.

Cons

  • Commercial (not free).
  • Some features required additional setup (I could not get Tomcat working, boo).

Overall, we are leaning towards Netbeans at the moment, with IntelliJ IDEA as a runner up. Getting Eclipse configured with all of the proper plugins seems like too much of a barrier for entry. 

The Visual Designer tools in Netbeans aren't much of a plus for me as I don't normally like designer tools in production, but they are helpful when you are learning your way around a new platform.

After we choose an IDE the next will be choosing a web framework. With JSP, Struts, Spring, and JSF to choose from, it's a crowded field. JSF seems to be the bees-knees, but Spring has it's supporters too. Even limiting the decision to JSF, there are over 50 implementations out there, each with it's own specialty/features/quirks. That's quite a lot to choose from.

Life as a Java Developer

In a stunning turn of events I get to be a Java developer for a while. We have a big client project (which we are all very excited to work on) that has to be done in Java as dictated by the needs of the client, which I can understand. It seems most people seem to go from Java to .Net, but for me it's the other way around. It will be interesting to see the other side of the fence.

It's a little intimidating, but I'm excited by the opportunity to learn a new (to me) technology.

322px-Java_Logo.svg

Still Here

I'm still here, I have not disappeared again. I have several posts in the pipeline, but I am still trying to establish better posting habits.

Case of the missing Postback in IE

Here's one with a simple solution that took me way longer to figure out than it should have.

We recently ported our internal intranet over to ASP.NET 2 (I know it's 2008, but it was a big project). For the most part this went smoothly, but a few minor issues appeared. One of these issues was with a custom server control that managed data paging. The control would draw the appropriate number of link buttons, when a button was clicked it generated a postback and called a SelectedPageChanged event to do whatever was required.

Because this is a custom control, I had to manually wire up the postback event:

   1:  newLinkBtn.Attributes.Add("onclick", 
   2:      Page.ClientScript.GetPostBackEventReference(this, argument));

This worked great in ASP.NET 1.1, and even after the port worked fine in Firefox and Safari. IE however showed some very strange behavior. It was refreshing the page but nothing was happening, which is very strange considering the code was all server side. There shouldn't have been any differences in browser behavior.

My first step was to update the code to use the ASP.NET 2 ClientScript tools:

   1:  newLinkBtn.OnClientClick = 
   2:      Page.ClientScript.GetPostBackClientHyperlink(this, argument);

Which didn't help. Stepping through the debugger, I saw that the page lifecycle was happening twice. The first time everything happened as expected, however the second time, everything defaulted back to the first load. This left me scratching my head for a while (longer than I cared to admit). I wish I could say I came up with the solution myself, but some googling led me to this post on msdner.net.  Simply appending a return statement solved my problem:

   1:  newLinkBtn.OnClientClick = 
   2:      Page.ClientScript.GetPostBackClientHyperlink(this, argument);   
   3:  newLinkBtn.OnClientClick += ";return false;";

In a nutshell, if you manually wire up a GetPostBackClientHyperLink (or GetPostBackEventReference), it will no longer provide a safety return statement. I could get mad at this behavior, but I see some benefit in being able to chain your own javascript to the PostBack event... if it worked consistently in all browsers. As it is this behavior only cropped up in IE (both 6 and 7), which made it quite a pain to figure out.

Back among the Living

So here it is, over two years since my last post. I've been quite busy in the meantime. Marriage, new house, a puppy, and oh, a baby! You can ready all about them at our new blog over at cookfamilystl.com.

Please bare with me as I dust off the cobwebs and refocus my blog on my. I intend to be a bit more regular updating, though I'm still working out on just how often that will be, but I'm aiming for at least twice a week.

Even though I have over 8 years of experience under my belt, I consider this very much a learning blog. I would like to share my thoughts as I explore programming and development and I hope I can share some of my passion or even inspire others in the process.

Thank you for reading.

Dynamic Server Controls & INamingContainer

It turns out that creating a custom server control that uses dynamic controls (controls added at runtime) is a huge pain in the ass. Add to that INamingContainer, which is virtually a necessity when making a composite control (it lets you have more than one copy of the server control on the page by guaranteeing that the child controls have unique id's) completely screws around with control's life-cycle, and you have one frustrated developer..

It's taken me entirely too long to create my data-paging server control, which simply creates the buttons you need to page through data (First, Prev, 1, 2, 3, Next, Last - etc) and provides an event for when the user clicks a button. It doesn't do the actual data-paging, just the controls so it should have been a simple control to write. Nope, I had to try just about every trick and lame technique in the book to get it to work the way I want. Along the way I tried such things as serializing out the settings to a hidden field (essentially creating my own custom viewstate), so that I could re-instantiate my controls before the events are supposed to fire. Turns out that way doesn't work so hot if you need to hide the control for whatever reason (hidden panel, etc), since the hidden field won't get included in the page. I also tried to tap into virtually every part of the control's life-cycle, which ultimately useless, turned out to be good for learning how things worked, inserting hidden fields, or creating and re-creating controls at different points.

Finally I have something that works, though it's not without it's share of shortcuts. I ultimately borrowed some idea and code from Dennis Bauer's DynamicControlsPlaceHolder, to re-create my dynamic controls out of the viewstate on a postback. The downside to this technique is that it doesn't re-wire the events properly, and even worse, you loose command arguments (which is what I used to determine which page button the user clicked on). So I had to work around that by storing some extra info into the persistenceString (a string that is passed along that tracks which controls to restore).

So once the control is loaded, I override CreateChildControls to create the final controls the user sees. I do this by calling this.Controls.Clear() to wipe out the controls that were created by from the viewstate (which could be different depending on which page the user clicked on). It's not great, but it's much easier and probably faster than comparing the new controls that will be generated to the existing ones and adding or removing ones that don't match up.

It would be nice if there was some way to detect which button was clicked so I could only restore that control to capture the event, but I don't know if that's possible. So it now works with only instantiating the controls a maximum of twice per page load, which is an improvement over earlier versions.

All of the leaves my final workaround for INamingContainer. As mentioned above using INamingContainer causes the control life-cycle events to be called in a different order. This meant that my CreateChildControls was being called after my event was firing, the event which set the current page that the CreateChildControls relied upon. That was a problem. I could have forced a call to re-create the child controls after my event fired, but that would be adding a lot of overhead to an already inefficient system by having to re-create the controls 3 times instead of two.

So I ended up manually setting all of the control id's so that they used the parent control's ClientID. This was essentially what INamingContainer did, sans the odd life-cycle changes. It wasn't as big a deal as it could have been since I had to explicitly set the control id's for the DynamicControlsPlaceHolder code to work anyway.

It's not pretty, but it works. I can put as many pagingcontrols on a page as I want (say at the top and bottom of a repeater), even hide them and it all works.  I can't imagine having to do anything more complex with dynamic controls in a server since this one was such a pain. On the upside I learned many of the finer points of creating server controls and the next one I write should go a little more smoothly.

Download Battlestar Galactica ... Legally!

It has just come to my attention that you can download and watch the first episode of the new Battlestar Galactic series (hands-down the best SciFi show on TV in years) for free. The downside is it's in RealPlayer format, but you can always use RealAlternative.

If only you could download Arrested Development for free (no doubt the best Comedy on TV today).

«August»
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456