How To Add a Custom JSP Tag Library to JDeveloper 10g

Written by Chris Schalk, Oracle Corporation
February 2004

Introduction

Even though JDeveloper 10g integrates many widely popular and powerful JSP tag libraries such as the JSP Standard Tag Libraries (JSTL) and the Struts tag libraries, it is also possible to integrate externally developed JSP tag libraries into JDeveloper's development environment. This How To steps through the process of downloading an externally developed custom tag library and integrating into JDeveloper's development environment. I will also show some of the cool support such as tag completion and rendered tags in the JSP visual editor.

Downloading a JSP Taglib

For this exercise I will download the Jakarta "Input" tag library which can be found at:
http://jakarta.apache.org/taglibs/doc/input-doc/intro.html

  1. The Jakarta Input tag library is a very simple, open source tag library which generates HTML input fields at runtime.

    I'll download a current build in zipped format from :
    http://cvs.apache.org/builds/jakarta-taglibs/nightly/projects/input/
    and extract the contents into a local directory:
    d:\input_taglib\
  2. I will refer to this location later when I add it to JDeveloper.

Adding the Input Tag Library to JDeveloper

Now it's time to integrate out external tag library into JDeveloper. This is a 2 step process. First we'll create a "Input Taglib" system library which is simply a reference to the location of the tag library's jar file(s), and then we'll add the Input tags themselves to the Component Palette.

  1. Create a JDeveloper "Input Taglib" library.
    -Select Tools-> Manage Libraries
    -Select "System Libraries" and click "New"
    -Name the library "Input Taglib"
    -In the "Class Path:" Add taglibs-input.jar located in your download directory: "d:\input_taglib\..".
  2. Register the taglib descriptor file (TLD) with JDeveloper and add the tags to the Component Palette.
    -Again, select Tools-> Manage Libraries
    -This time select the "JSP Tag Libraries" tab and click "New"

    -Specify the following
    TLD File: D:\input_taglib\taglibs-input.tld (Use the Browse button.)
    Libraries: Input Taglib (Use Browse button and select your "Input Taglib" library created in the previous step.)
    URI: http://jakarta.apache.org/taglibs/input-1.0 (should be autofilled)
    Prefix: input (You can define this yourself.)
    Leave the "Execute tags in visual editor" checkbox unchecked and click "Ok".
    Note: By leaving the "Execute tags..." checkbox unchecked, you are turning off the JSF tag visualization feature. This feature allows you to actually execute the tag when it's viewed in the JSP visual editor to provide a more intuitive rendered experience. In practice it is best to start out with this turned off, so you can work with tags in their non-runtime rendered, iconic state and then later, turn on the rendering to get a better view of the application.

  3. The next step is to add the tags to the palette. (Note: These next steps are simplified in the production version of 10g.)

  4. On the main menu select, "Tools->Configure Palette..."

  5. Under the "Pages:" window on the left, click "Add..".

  6. Name the new Component Palette page "Input Tags" and select "jsp" as the page type.

  7. In the same dialog, click "Add..." under the "Components" window on the right side. These are the actual components (in our case, tags) which will appear on the new Palette page.

  8. In the Taglib dialog, select the "Input" tag library in the tree and click "Ok". A dialog will appear, "Install all JSP(s) tags?", click "Yes" to install them onto the Palette.

  9. Click "Ok" to dismiss the Palette configuration dialog. Now when you edit JSP pages, you will see your new "Input Tags" Component Palette Page.

  10. That's it! You're done! You can now use the Input tags in JDeveloper.

Working with the Input Tags in JDeveloper

Now we'll use the new Input tags in a simple application.

Let's start by creating an application Workspace

  1. File->New->General->Application Workspace..
  2. You can name your application "InputFun" and for the Application Template, select "Custom Application [ All Technologies ]". This will create a new Workspace with a single empty project: "project".
  3. In your project create a new JSP: File -> New->Web-Tier->JavaServer Pages -> JSP page.
  4. In your new JSP you can optionally add some text like "Working with the Input Tags" and using the toolbar format the text to <h2>.
  5. In the Component Palette, select the new Palette Page "Input Tags" in the dropdown list.
  6. Drag and drop a "text" tag into your JSP. Set the attributes:
    name: mytext
    default: This is a text field tag..
  7. Click Ok. The tag appears on the page in an iconic form.
  8. This is the default rendering JSP tags in the visual editor. Now let's turn on the execution setting to render the tag in the visual editor...
  9. Select Tools->Manage Libraries.
  10. Click on the "JSP Tag Libraries" tab.
  11. Click on the "Input" tag library, select the checkbox: "Execute Tags in JSP Visual Editor". This will now cause the Input tags to execute and render themselves in the visual editor.
  12. Click "Ok" to dismiss the dialog.
  13. Now refresh the JSP visual editor by click on the refresh button  on the upper left corner of the visual editor.
  14. You should now see your text field rendered as a text field in the visual editor!
  15. Now try dropping a "textarea" tag onto your page with attributes:
    name: mytextarea
    default: This is a text area tag...
  16. Click "Ok".
  17. You should then see your new text area!

Tag Completion

Now that we've added the JSP tag library to JDeveloper we also get some helpful features in the Code Editor as well such as JSP taglib Code Completion. Let's try this out..

  1. Click on the "Code" tab at the bottom of the JSP editor. You should now see your JSP code in the code editor.
  2. In a new line enter the following text: "<Input:". You should then see a listing of all available tags in this tag library.
  3. Go ahead and select a tag. (password).
  4. After you the password tag, enter a space. You will then see a list of attributes for the password tag.
  5. Select the "name" attribute and define a name. Enter a space..
  6. You'll notice that the Code Completion will now show the list of the remaining attributes.. Enter a "default" value and then close off the tag by entering "/>".
  7. switch over to the "Design" view and you'll see your new "password" tag.
  8. That's it for now. Feel free to experiment with other tags in the tag library. Also remember that you can always turn off the rendering of the tags if you prefer to see them in iconic form.

Summary

As you can see, it is possible to integrate externally developed JSP tag libraries into both JSP visual and coding development environments in JDeveloper.
Have fun integrating other JSP tag libraries into JDeveloper!

Discuss this How To in this Discussion Thread on OTN Forums:

For further reference:

 

false ,,,,,,,,,,,,,,,