Skip to end of metadata
Go to start of metadata

We've created the model - the Form - for our document, and the controller - the Action. Wonderful! That leaves us simply...the view. HTML. div's and CSS's and JavaScripts...oh my. Thankfully, JSP creation is simplified in KFS, just as creating the Struts Form and Action was simplified. Naturally, JSP pages can't inherit from other JSP pages, of course, but they can include other JSP pages and use JSP-defined taglets. Both these strategies ease the JSP creation process considerably.

Creating a JSP page

Let's look at a JSP page for a transactional document. This is InternalBilling.jsp, the JSP page for org.kuali.module.financial.document.InternalBillingDocument. It lives in the work/web-root/jsp/modules/financial/ directory.

Looks semi-painless, right? Let's take a look at each piece.

Line 1 is a JSP include directive, which includes the kfsTldHeader.jsp. kfsTldHeader.jsp basically imports all of our taglibs, and since those are so heavily used in Kuali; including the file is highly convenient, so when we create JSP pages, we'll include that file as well.

Lines 2 and 14 declare the kul:documentPage. As we remember, each JSP tag or taglet has a name space; tags from Kuali Rice use the "kul" namespace and each module in KFS has its own namespace (like, yes, "gl" and "fin"). The "html" namespace comes from Struts, of course.

Back to the documentPage tag. This is the tag that declares the page. The documentPage tag has a number of attributes, but the most important ones are used here. showDocumentInfo decides if the page should show "document" information, such as help links for the document. htmlFormAction is the name of the KFS Struts mapping that requests should be posted to. documentTypeName is the name of the document, as defined in the data dictionary. renderMulitpart means that the form tag should be a multi-part form, so that, for instance, files could be uploaded to it (since all documents with notes can have file uploads, it's typically wise to set this to true). Finally, showTabButtons either shows or hides the "show" or "hide" buttons on tabs.

Lines 4 and 5 are also important to require on every page: they place any hidden fields into the page, such as the document number, and documentOverview displays the "header" on the document, which shows the document title, what document number the document is, and so on.

Lines 6, 7, and 8 are specific to internal billing: basically they create a tab for accounting lines to show up, a tab for billed items, and finally, the tab for pending ledger entries.

Lines 9 - 13 are common to most pages. kul:notes shows the Notes tab and kul:adHocRecipients renders the Ad Hoc Routing tab. kul:panelFooter draws the bottom of the page above the buttons; neglect this and our page will look lame, forcing graphic designers to laugh at us. The kul:documentControls shows the workflow buttons - the submit button, save button, cancel button - whatever buttons should be turned on for our document.

As we can see, using tag libraries saves us a lot of effort. Therefore, we're going to take a look at commonly used tags, and then explore how to create a tag ourself.

Tags to know

Here's a list of helpful tags to know when we create our own JSP pages or taglets:

  • kul:documentPage - if our page is a view for a document, then we want to use the kul:documentPage tag to set up the page for us; this page acts a wrapper for all the other tags within our document page
  • kul:page - likewise, if our page is not a view for a specific document, then we want to use the kul:page tag. This tag has many more attributes so that it is more flexible, but most use of it will look a lot like kul:documentPage
  • kul:hiddenDocumentFields - again, this is for pages which are the view for a transactional document; this tag places hidden fields with the document number and several other document attributes, such as objectId and versionNumber
  • kul:documentOverview - this draws the header, which is to say the document title and the upper right hand block of information including document number and initiator, for the given document
  • kul:panelFooter - again, this draws the bottom curve on a page just before the buttons. It makes our pages look nice.
  • kul:documentControls - these are the traditional buttons for a document, turned on and off by the document authorizer.
  • kul:notes - this is a tab that allows us to add notes to our document
  • kul:adHocRecipients - this is a tab that allows us to add ad hoc workflow recipients to a document
  • kul:tab - this tag draws a tab for us, so that we can create our own. We'll take a closer look when we examine how to build a tag file, but basically, the HTML we want to display within a given tab is wrapped within this tag. Annoying, we also need to wrap that content within a <div class="tab-container" align="center"> tag.
  • kul:htmlControlAttribute - this very flexible tag is handed the name of a property on a document and the data dictionary entry for a document; it the displays the proper attribute for the given property, based on the attribute within the data dictionary. This tag has a lot of other interesting attributes as well.
  • kul:htmlAttributeLabel and kul:htmlAttributeHeaderCell - these two tags are handed the name of a property on a document and the data dictionary for the document, and then they display the label of the attribute as defined in the data dictionary. kul:htmlAttributeHeaderCell wraps its output in <th> tags.
  • fin:accountingLines - this wildly flexible tag shows the accounting lines for a document. More information on its uses can be found on the page about the Accounting document framework..
  • gl:generalLedgerPendingEntries - this tag shows the general ledger pending entries for a financial processing document

Each module defines its own set of tags that we will likely need to know as we work on the module itself. It is often useful to know the Struts taglibs, especially the html: and logic: taglibs. Finally, knowledge of the JSTL standard taglibs is very helpful as well.

Creating a taglet, or, The Return of TD

Now that we've got a library of tags, let's see how hard it is to create our own taglet. Because taglets throw us back to the land of HTML, the files get much, much larger, so we're going to show some extracts here, specifically from fin:items. All KFS tags belong in the work/web-root/WEB-INF/tags/{module code} directory; the module code for Financial Processing tags is "fin", so the items.tag file can be found in work/web-root/WEB-INF/tags/items.tag.

As we look through the tag, we see that the kfsTldHeader.jsp is once again included. After that, any attributes for the tag are declared; in this case, we've got only one attribute, editingMode, which is the document authorizer editing mode. Note that any tag can access the Form class under the variable KualiForm, and therefore, it can access the document as KualiForm.document.

Next, we see the tab for the items is created:

We give our tab a title ("Items"), we note whether it is open on default or not, and finally we create a tabErrorKey, which is the error paths of any errors to be displayed in this tab. In this case, any errors with the paths: "newItem*,document.item*" will be displayed in the tab. Note, by the way, that we can access any constants through KFSConstants. Cool.

Next, we retrieve any business object data dictionary entries we need to display business object or document fields on the page:

Once again, we have a magical singleton, DataDictionary, which holds all of the data dictionary entries.

Then we do some display:

This tag correctly has the div for the tab content. Headers must also be wrapped in divs. Finally, we open a table; tables on KFS forms should use the CSS class of "datatable".

Next, we need to show the header row for the table:

Notice the use of the kul:htmlAttributeHeaderCell tag.

Then, we show a row for the new item:

In this, it's important to point out a couple things. First of all, controls are drawn using the kul:htmlControlAttribute tag...except for the date field, which uses the kul:dateInput tag. Notice, too, that the "add" button uses the Struts-defined html:image tag to make a clickable image button.

The rest of the tag defines how to display the old lines of items, which is pretty similar to how the new item line is displayed (though instead of using "newItem." as the property, they use "document.items[KULRNE:${ctr}]." (all property names in kul: tags are relative to KualiForm). Finally, a total is displayed and the tab's div and kul:tab tag are closed:

If we're certain how a property should be displayed, it's certainly permissible to use the JSP EL ${...} syntax to display it.

That's our tag, then. How does it get used? Well, on InternalBilling.jsp, we see that it's use is pretty easy:

Viola! We have a tag and now can build a highly extensible, reusable view. And that means...our transactional document is done! Hooray!

Unable to render {include} The included page could not be found.
  • No labels