ADF Faces: Avoid Use of <jsp:include> Tag!

When reviewing ADF applications, I frequently see ADF Faces pages that use the <jsp:include/> tag to include another ADF Faces page fragment.

This is really old-school JSP programming and should be avoided:

  • Component id's in the included page fragment might conflict with component id's in the base page.
  • You cannot use it as a partial source or partial target in partial page refresh
  • You cannot use JSF expression language in the <jsp:param/> since it was designed for JSP, not JSF
  • You cannot customize this tag using MDS

It is much better to use the native ADF Faces <af:declarativeComponent> tag, which is a first-class UI Component:
  • It is a naming container with its own id property, you will never have id conflicts with the page using the component
  • It has a partialTriggers property and can be specified as partial target component by other UI components
  • You can pass parameters using custom properties (see below) or the <f:attribute> tag, and you can use JSF expression language to specify parameter values.
  • You can customize the component using MDS

So, replace code like this:

<jsp:include page="/includes/myIncludeFragment.jsff">
  <jsp:param name="myParam" value="myValue"/>
 </jsp:include>

with this:

<af:declarativeComponent id="dc0" viewId="/includes/myIncludeFragment.jsff" myParam="myValue"/>

Note the use of custom property "myParam" inside the tag, this property should be defined as attribute in the declarative component definition as shown below:

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:f="http://java.sun.com/jsf/core"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich" version="2.1">
    <af:componentDef var="attrs">
        <af:xmlContent>
            <component xmlns="http://xmlns.oracle.com/adf/faces/rich/component">
                <description>my fragment</description>
                <attribute>
                    <attribute-name>myParam</attribute-name>
                    <attribute-class>java.lang.String</attribute-class>
                    <required>true</required>
                </attribute>
            </component>
        </af:xmlContent>
        <!-- Actual content goes here-->
        <af:outputText value="#{attrs.myParam}"/>
    </af:componentDef>
</jsp:root>

Comments:

The issue with the unique component id can be solved using the f:subview component as well. However, no matter which solution you choose, one problem will remain: The PageDef file - assuming ADF is used - of the page fragment included to the parent is not read. So if ADF is in the picture then yes - avoid jsp:include - but use ADF templates or ADF Region to add the content. Frank

Posted by Frank Nimphius on September 29, 2010 at 09:27 PM PDT #

Frank, Thanks for the addition. To clarify for everyone: When using a jsp:include, the included file uses the page definition file of the base page. If this is OK for you, then use the declarativeComponent which also uses the page definition of the base page. If you need a separate page def for your included fragment , then follow Frank's suggestion: ADF template or region. Steven.

Posted by steven.davelaar on September 30, 2010 at 04:05 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Java EE Consultants - JHeadstart, ADF, JSF

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
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
   
       
Today