Jasper

Adding the '[[FEEDBACK_FORM]]' token

Immediately upon adding the form to your chosen template file, the next stage is to remove it. In place of the form, insert the custom token '[[FEEDBACK_FORM]]'. This token will be used to insert the form HTML, which will be held in a separate include file, as already mentioned. In fact the Jasper distribution already contains a template HTML file with this token, called 'feedback.html'. You can use this from now on if you wish.

The include file for the form should be the called 'feedback.html' file and should be placed in the 'template/_form/' directory. If you made no style or layout changes to the form in place, you have nothing more to do at this stage than create this file, once you have replaced the form HTML with the requisite token. If you have made amends, cut and paste the amended HTML into this new 'feedback.html' file. Remember to include the lowermost paragraph element containing the '[[MESSAGE]]' token.

In order to process this token, the easiest thing to do is to subclass the TemplateBase class. This is not strictly necessary, although very much advised. It is possible to use the TemplateBase class' process_token(...) method to interpret tokens other than those associated with hyperlinks and other such low level functionality, but it is hardly ideal.

Like the template HTML files, the TemplateMain class that subclasses the TemplateBase class and will pick up the custom token to include the feedback form is already present in the Jasper distribution. All that it is necessary to do is change the 'main' server process to use this class as opposed to the TemplateBase class. Do so now. A pseudo-code listing of the process_token(...) method of the TemplateMain class is given below:

function process_token ( match, props )
{
    if ( StringUtils.equals( match, "FEEDBACK_FORM" ) )
    {
        return ( FeedbackForm.process( props ) );
    }

    return ( super.process_token( match, props ) );
}

The FeedbackForm class is also part of the Jasper distribution and will be disected in a moment. Incidentally, this subclassing does not need to go on for ever. Usually two or three levels beyond the TemplateBase class is all that is required. The following diagram should make the program flow clear as it moves up from the outermost process_token(...) method to the innermost:

         TemplateHTML       |              ----► TemplateHTML.process_token(...) 
              ▲             |             |
              |             |             |
    "extends" |             |   "invokes" | 
              |             |             |
              |             |             |
         TemplateBase       |              ----- TemplateBase.process_token(...) ◄-----
              ▲             |                                                          |
              |             |                                                          |
    "extends" |             |                                                          | "invokes"
              |             |                                                          |
              |             |                                                          |
         TemplateMain        ------------------► TemplateMain.process_token(...) ------

If you want, comment out the call to the process method of the FeedbackForm class for the moment and in its place, either return a string, the 'token' parameter itself will do, or write it to the log file. Then refresh the page to verify that the new token is indeed being picked up.

Last updated: Sunday, 23rd October 2011, 07:10 PM

User comments:

There are none.

Leave a comment:

Display name Email address Content
Enable HTML content
PreviewSubmit