Sunday 4 February 2007

<af:page> bug or another tofu conspiracy?

Ever jump to the wrong conclusion just because it's easier? I'm that sort of guy. For instance if the milk is off, I leap right in and rant about the soy milk conspirators, how they've poisoned the dairy industry, and that they're the source of all the world's woes (including tofu).

And why should programming be any different? I've been having an on/off battle with the ADF Faces <af:page> and <af:panelPage> tags to render correctly in JDeveloper. So far I've blamed the whole GM crowd, Cobol programmers, and John Howard for good measure.

....but as usual it turns out the problem, might just, um, be me.

In JSF projects I regularly setup an <af:page> as detailed in section 19.2 Using Dynamic Menus of the JDev for 4GL/Forms guide to create dynamic menu structures. And I would expect to see this menu structure:

However, when quickly demonstrating the component rather than taking time to do it properly, I often receive the following look and feel at runtime when I drill down inside the menu structure?


For my first menu page it usually works as I expected, but for my other menu pages that I created on the fly, well..... where did that "Skip navigation elements to page contents" hyperlink come from? Why does it say SelectPage2 rather than showing the commandMenuItem? Why is the menu component only half rendered? Why doesn't it happen all the time? Why? Why? Why?

After some head scratching, a few serious but failed attempts to blame Larry, and a little spare time to actually sit down and look at the problem, I worked out it was my mistake (again).

When you create a JSF page within JDeveloper, the empty page often looks like this (I've trimmed the surrounding tags for simplicity):

<f:view>
  <html>
    <head>
      <meta http-equiv=\"Content-Type\" 
            content=\"text/html; charset=windows-1252\"/>
      <title>My Page Title</title>
    </head>
    <body><h:form></h:form></body>
  </html>
</f:view>

From here, on the first page I'd start dragging in data-bound components from the Data Control Palette, then add my <af:page> control, ending up with something like this:

<f:view>
  <afh:html>
    <afh:head title=\"Page 1\">
      <meta http-equiv=\"Content-Type\" 
            content=\"text/html; charset=windows-1252\"/>
    </afh:head>
    <afh:body>
      <h:form>
        <af:page title=\"Page 1\" var=\"node\" 
                 value=\"#{menuModel.model}\"> 
          <f:facet name=\"nodeStamp\">            
            <af:commandMenuItem text=\"#{node.label}\" 
                                action=\"#{node.getOutcome}\"/>
          </f:facet>          
          .... some data-bound components ....
        </af:page>
      </h:form>
    </afh:body>
  </afh:html>
</f:view>

Note that JDeveloper converts the original <html>, <head> and <body> tags to ADF Faces <afh:html>, <afh:head> and <afh:body> tags respectively when we've dragged in the data-bound components.

And that's where the issue lies, because later I wanted to add the <af:page> code that I'd written to other pages. So when I created a new page, I'd copy across the <af:page> code, but forgot to copy the <afh:html>, <afh:head> and <afh:body> tags. Those tags among other things take responsibility for loading in the ADF Faces Skin files (CSS style sheets), and a bunch of other smarts needed by such tags as the <af:page> tag, so I needed to copy these additional tags too.

So hopefully next time you're attempting to demonstrate the powers of ADF Faces and JDeveloper, you wont blame everybody but the coder at hand like I do.

4 comments:

Noons said...

why is it that everytime I read a description of someone trying a process in one of the myriad java "technologies", it always reminds me of Bobcat Goldwaith?

Chris Muir said...

Wow, I never thought one of my posts would be associated with a star from a Police Academy movie ;)

Noons said...

actually, this was not directed at the contents of your post, sorry if it came out that way.

it's indeed rather directed at this deranged technology where nothing is documented, or standardized, or minimally structured so that folks can quickly take advantage of something new. it's all basically suck-it-and-see, or cut-and-paste from some convenient recipe book.


and why it reminds me of how that guy talks.

Chris Muir said...

Ha, no worries, no offense taken.

CM.