Dive into Oracle ADF

Send me a mail
 Dive into Oracle ADF   Click to see the XML version of this web page.   (Updated: 2/3/2008; 9:22:09 PM.)
Tips and tricks from Steve Muench on Oracle ADF Framework and JDeveloper IDE

Search blog with Google:
 

Search BC4J JavaDoc:
 

April 2007
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          
Mar   May

Get Firefox!

Thursday, April 26, 2007

A user wrote in to ask why his breakpoint set in the ADF PageLifecycleImpl class' prepareRender() method would fire more than once per request if his page included any images. In fact, he noticed that he would hit the breakpoint once as expected, and then again (unexpectedly) once for each image on the page. That is, if his page included three images then he'd hit this breakpoint four times. After a little digging and asking an ADF Faces team member, we got to the bottom of the problem. If you're interested in avoiding this unexpected overhead for images in your own application, read on:

A typical ADF Faces application has the FacesServlet configured in web.xml to handle requests to the application server whose URL matches "/faces/*" via the following web.xml entry:

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>

I learned yesterday that if you use ADF Faces components like <af:objectImage> to display images using a relative URL like this:

<!-- Notice no leading forward slash in the relative image URL -->
<af:objectImage height="14" width="16" source="images/MyIcon.gif"/>

then the actual image URL that your browser will request will end up looking like this:

http://yourserver/YourContextRoot/faces/images/MyIcon.gif

which, due to its matching the "/faces/*" URL pattern, causes the Faces Servlet (and hence the rest of the ADF page lifecycle that is "wired" into it as a phase listener) to inadvertently kick-in again while serving up each such image. This is definitely not great for performance, so make sure that you use relative URL's that begin with a leading forward-slash like this instead:

<!-- Notice leading forward slash in the relative image URL -->
<af:objectImage height="14" width="16" source="/images/MyIcon.gif"/>

This will cause ADF Faces to generate a URL that automatically includes the J2EE Context Root, but leaves out the "/faces" part of the URL. This avoids the unnecessary triggering of the Faces servlet for serving up your images.


4:48:36 PM    



© Copyright 2008 Steve Muench.