There was recently a post on TheServerSide that pointed to an article on DeveloperWorks titled, “Pure servlets: Rethink the view” by Jason Van Cleve. I read it, I read some of the reaction to the TSS thread. (read on..)

The Code

Here’s some code from the sample application that is attached to the article. My first reaction was astonishment. If you are reading this, and you think that code like this deserves to be written, stand up and defend it. I see something like the following and I shudder to think of the co-workers who have had to suffer through Java producing HTML code at work:

 protected void doBoth(HttpServletRequest request, HttpServletResponse response,
        HttpSession session, MadnessWriter out) throws ServletException, IOException
    {
    GameManager gameMan = GameManager.GetInstance();
    Game[] games = gameMan.getGamesInBracketOutputOrder();
    TeamManager teamMan = TeamManager.GetInstance();
    Map teams = teamMan.selectAllAsMap();
    out.printPreContent();
    out.printMenu(null);
    out.printBeginBox(true);
    out.printDIV("heading", "Select Game Winners");
    out.print(NL);
    out.printBeginFORM(URL_EDIT_WINNERS_ACTION);
    out.printBeginTABLE(0, 0, 0, "100%", "class=\"scoreboard\"");
    out.print(NL + TR);
    for (int i = 0; i < ROUND_NAMES.length; i++)
      {
      out.print(TH);
      out.print(ROUND_NAMES[i]);
      out.print(END_TH);
      }
    out.print(END_TR + TR);
    out.printBeginTD(null, "firstColumn");
    boolean firstInColumn = true;
    for (int i = 0; i < games.length; i++)
      {
      if ((games[i].getTeam1ID() >= 0) && (games[i].getTeam2ID() >= 0))
        {
        if (!firstInColumn)
          out.print(BR + BR + NL);
        firstInColumn = false;
        out.print("Game ");
        out.print(games[i].getPosition() + 1);
        out.print(":" + BR);
        out.printBeginSELECT(P_GAME + games[i].getID(), null);
        String winningTeamID = Integer.toString(games[i].getWinningTeamID());
        out.printOPTION("-1", "(unknown)", winningTeamID);
        Team team = (Team)(teams.get(new Integer(games[i].getTeam1ID())));
        out.printOPTION(Integer.toString(team.getID()), team.getHome(), winningTeamID);
        team = (Team)(teams.get(new Integer(games[i].getTeam2ID())));
        out.printOPTION(Integer.toString(team.getID()), team.getHome(), winningTeamID);
        out.print(NL + END_SELECT + NL);
        }
      if ((i == 31) || (i == 47) || (i == 55) || (i == 59) || (i == 61))
        {
        out.print(NBSP + END_TD + TD);
        firstInColumn = true;
        }
      }
    out.print(NBSP + END_TD + END_TR);
    out.printBeginTR("bottom");
    out.printBeginTD(6, 1);
    out.print(BR);
    out.printSUBMIT(P_SAVE, "Save");
    out.print(END_TD + END_TR + END_TABLE + END_FORM);
    out.printEndBox();
    out.printBeginBox();
    out.printMenuItem(URL_EMAIL_PICKS, "Email All Picks To All Players", "Send an email to active players, showing all their picks.");
    out.printMenuItem(URL_EMAIL_SCORES, "Email Scores To All Players", "Email the Scoreboard to all active players.");
    out.printEndBox();
    out.printPostContent();
    }

In the understatement of the year, he talks of this approach as being “contrary to the modern orthodoxy” as if Matt Raible, Bill Burke, and Craig McClanahan sitting atop high thrones in the church of J2EE web applications, ignore all input from the laity. This religious reference is unwarranted; not generating HTML from Java code is as much a component of the “modern orthodoxy” as having redundant jet engines is a part of the “modern orthodoxy” of general aviation. It isn’t a belief as much as it is a common engineering practice developed over the better part of a decade. Mixing Logic + HTML? sparingly, I do it all the time in RoR, but when I do it, I don’t create the sort of Java-developer madness proposed by this author. Look at the code above, and then read the following tidbits of genius:

That END_TABLE_3 constant is just shorthand for a closing TD, TR, and TABLE combination. It’s a cakewalk, once you get the hang of it, but the terseness of this syntax relies on good HTML design, which means using it for structure only and keeping as much style as possible in the style sheet.

A Diplomatic Out: So… This is an April Fool’s Joke, right?

All this because someone decided that JSP and taglibs are distracting. Many of us believe that JSP and Taglibs are distracting, but instead of reverting back to the late nineties we look for alternatives in the form of Velocity or FreeMarker. But, if you don’t like templates don’t stop there, instead of adopting a template-based approach to the view, there is a whole host of component-oriented options like Faces, Tapestry, and Wicket. My point is not to advocate censorship of this idea, yes it is possible that someone might find it useful to skip a web framework and just write Java that spits out HTML, but to advocate for this seems like something other than the output of a whimsical contrarian. It just seems like a joke, and, it is for that reason, that I’m going to have to assume that this was a DeveloperWorks attempt at an early April Fools Joke.

If this isn’t a joke, it is a commentary on the state of Java “journalism”, how does something like this make it through the editorial filters of DeveloperWorks, and how does it become something trumpeted by the TSS newsletter? If it isn’t a joke, then I’m in a bad mood.