Deploying an app with static functions

The only thing that’s new here is the “myFunctions.tld” file. It has to be somewhere within WEB-INF or one of its subdirectories (unless it’s deployed in a JAR file, but we’ll talk about that later in the book). Here, because this app is so simple, we have both the DD (web.xml) and the TLD (myFunctions.tld) at the top level of WEB-INF, but you could organize them into subdirectories.

The key point is that the class with the static function MUST be available to the app, so... for now, you know that putting it inside WEB-INF/classes will work. And remember that in the taglib directive in the JSP, we specified a URI that matches the URI declared in the TLD. For now, think of the URI as simply whatever you decided to name the TLD. It’s just a name. In the next chapter on using custom tags, we’ll go into all the details about TLDs and URIs.

image with no caption

The class with the function (the public static method) must be available to the web app just like servlet, bean, and listener classes. That means somewhere in WEB-INF/classes...

Put the TLD file somewhere under WEB-INF, and make sure the taglib directive in the JSP includes a uri attribute that matches the <uri> element in the TLD.

Watch it!

The METHOD name is not the same as the FUNCTION name!

Memorize the relationships between the class, the TLD, and the JSP. Most importantly, remember that the METHOD name does NOT have to match the FUNCTION name. What you use in EL to invoke the function must match the <name> element in the <function> declaration in the TLD. The element for <function-signature> is there to tell the Container which method to call when the JSP uses the <name>.

And the only place the class name appears (besides the class declaration itself) is in the <function-class> element.

Oh, and while we’re here... did you notice that everything in the <function> tag has the word <function> in it EXCEPT for the <name> tag? So, don’t be fooled by this:

image with no caption

The correct tag for the function name is <name>!

image with no caption
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset