99 Bottles of ADF

Three years ago I blogged about the site 99 Bottles of Beer, which is a site dedicated to generating the lyrics of that oh so annoying song in every programming language known... currently over 1500 languages have been submitted. It's a surprisingly useful exercise when learning a new language... loops, text output, conditionals, etc.

Three years ago I submitted IdocScript to their library. I recently came across it again, and was shocked to find that nobody has submitted ADf yet! Geek rules state that ADF cant be an "official" language until it's on that site, so I had to do my part. Below is my humble submission:

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <jsp:directive.page contentType="text/html;charset=UTF-8"/>
  <f:view>
    <af:document id="d1">    
      <af:form id="f1">
        <af:panelGroupLayout id="pgl" layout="vertical">
          <af:forEach begin="1" end="98" varStatus="bottle">
            <af:outputText value="#{100 - bottle.index} bottles of beer on the wall, #{100 - bottle.index} bottles of beer!" id="ot1"/>
            <af:outputText value="take one down, pass it around," id="ot2"/>
            <af:outputText value="#{99 - bottle.index} bottles of beer on the wall!" id="ot3"/>
            <af:spacer width="10" height="10" id="s1"/>
          </af:forEach>
          <af:outputText value="1 bottle of beer on the wall, 1 bottle of beer!" id="ot4"/>
          <af:outputText value="take one down, pass it around," id="ot5"/>
          <af:outputText value="no more bottles of beer on the wall!" id="ot6"/>
        </af:panelGroupLayout>
      </af:form>
    </af:document>
  </f:view>
</jsp:root>

I'm using a pretty basic program here... I'm using a vertical af:panelGroupLayout, an af:forEach tag to loop, and an af:outputText tag with expression language to print out the index. The af:spacer is there just to make it easier to read. Unfortunately, the af:ForEach tag does not iterate backwards (setting the 'step' attribute to '-1' makes it bark at me), so I have to subtract the index from 100 to get the number of bottles of beer on the wall.

This mainly demonstrates how expression language, loops, and conditionals can be used on an ADF Faces page. Another option would be to generate an array in a backing bean and bind that to the af:forEach tag, but I wanted to keep it all in one file.

Not sure if this will ever be officially accepted... because there are over 1117 languages are in their approval queue! I guess after IdocScript was admitted, the site got so popular they just couldn't keep up with demand...

Recent comments