There, I said it. I don’t know about you, but every time I read another article where someone touts their java web framework for its likeness to programming in Swing I want to vomit all over my monitor – and then the person doing the touting.

Swing? …Really?

Before I make all Swing developers / lovers hate me I should say that there are many nice things about Swing as well, and some very clever people doing really cool stuff with it – but it has a number of hateful warts to it as with any technology…and this is before you bring the abstraction to web applications. (which have slim to no correlation to desktop applications)

What’s the worst part about Swing programming for me personally? The layout managers…sigh….Yeah, you know exactly what I’m talking about. GridBag#$@#$# damnit! Where are the rendering hints yo? Signal/slot connections? (it’s a pity the closure stuff wasn’t there in the beginning – function pointers are useful sometimes)

So…with that all in mind – what is the most important end-product that a web based framework should probably make pretty damn important? HTML! Yes, and…what does HTML dictate? Layout / content / everything.

What kind of framework makes HTML/javascript less important than your java code? The kinds that emulate Swing perhaps? I’m sorry but a “Panel” doesn’t do justice to all the nuances and behaviours possible with a block level HTML element.

This is one area that I don’t think enough people really appreciate / know about Tapestry. It really does care about your HTML and making managing it as easy / natural for you as possible. For instance, did you know that you can do stuff like this in a Tapestry html template, and that for the most part almost any component in the framework can automatically do this because it’s built in?

<ul class="items">
 <li jwcid="@For" source="ognl:users" value="ognl:user" class="itemList view" style="margin-right: 10%">
  <span jwcid="@Insert" value="ognl:user.name" />
  </li>
</ul>

The output from this example would pretty much look like this:

<ul class="items">
 <li class="itemList view" style="margin-right: 10%">
    Fred Smith
  </li>
  <li class="itemList view" style="margin-right: 10%">
    Bob Johnson
   </li>
</ul>

Did you notice how the css class and style attributes were written out exactly as I had typed them? And that the components involved know nothing about these attributes or that they’re being used? It’s a small thing I know, but it makes a big difference in every day development. It’s also a feature that doesn’t exist in a lot of web frameworks. Perhaps because they’d prefer to do it in java? (wtf is wrong with you?):

void someGodAwfulMethod(DomWriter dom) {
  // i think in reality it's even harder than this,  but I can't make myself do it even in pseudo code
  for (User in getSource()) {
      dom.writeSomeCrap("<li>").writeSomeMore(user.getName()).andMore("</li>");
  }
}

   ..........or how about?
void paintMyHtml(Context context) {
     ListPanel panel = new ListPanel("What were they thinking?");

     for (User in getSource()) {
         panel.addItem(new ListItem(user.getName()));
     }
  }

Those examples are contrived but are probably close enough to get the general picture. Want to edit that html just a little bit to exert some more control over it? Too bad. Want to just be able to layout your html using “html and css” of all things? Too bad. Better flex those fingers and get ready to write some more java code buddy. You do like writing Java code right? I mean, you enjoy the actual act of typing of lines and lines of code for the sure joy of it?

end of rant..


  1. Gravatar IconMikael Grev

    Regarding Layout Managers, have you tried MigLayout? It is almost CSS for Swing. And it is already on the Top25 RFEs for Java 7…

  2. Gravatar Iconjkuhnert

    @Mikael: Yeah I had heard about something related to CSS layout of Swing stuff. Isn’t Ben working on that one too? Sounds promising – anything has to be better than what we have now. ;)

  1. 1 Swing links of the week: February 3, 2008

    [...] Kuhnert writes a rather misguided rant about Swing. The three points that he mentions as Swing’s worst parts are quite easily [...]

  2. 2 opencomponentry » Blog Archive » painting by numbers, or how html cowards hide behind CSS

    [...] My new friend Kirill has reminded me of another constant source of vomiting when he made some observations about my anti-Swing web development rant. [...]



Leave a Comment