Enabling the portlet URL JSP Cache using the POST method
Portlet URL caching using the POST method requires an additional event handler tag to be added to the onSubmit event of an HTML form. The enablement should be performed in the original portlet JSP file.
Procedure
- At the top of the portlet JSP file, declare the new cache tag library using cache as the prefix.
- For all portlet action URLs that use the GET method, substitute
all occurrences of
<portlet:actionURL>
with<cache:actionURL>
. - For all portlet render URLs, substitute all occurrences
of
<portlet:renderURL>
with<cache:renderURL>
. - In each of the substituted portlet URL tags from step 1
and 2, add an additional tag attribute defining the method type. For
example,
method=POST
. - Associate a JavaScript function to the HTML Form submit
event by declaring another cache tag called
<cache:submit>
to the onSubmit attribute of the HTML Form. The name of this submit cache tag must be the variable name of the portlet URL that is assigned for this Form submission.
Results
When WebSphere Portal renders this portlet JSP file for the first time upon a cache miss, the following sequence of events occurs:
- The portlet JSP file is compiled into byte code.
- If the cache tag detects no DCP object associated with the current page context, a new DCP is created and initialized. Each cache tag is responsible to register all its associated properties, such as parameters and the name of the variable to store the portlet URL, to the DCP for the callback handler to know how to regenerate the given portlet URL upon a cache hit.
- Unlike the GET method, when the cache tag is set to use the POST
method, instead of returning a generated JavaScript text string, the
cache tag generates a JavaScript function which essentially does the
same thing as GET. This JavaScript function can override the initial
portlet URL to submit the HTML Form with another JavaScript variable
if it exists.The generated JavaScript function is in the following format:Where
function functionName(f) { if (typeof(variableName) == 'undefined') { f.action = "/wps/portal/…"; } else { f.action = variableName; } f.submit(); }
variableName
is another JavaScript variable that is generated by the DCP upon the next cache hit. As DCP is not called on a cache miss, this JavaScriptvariableName
is not yet defined and therefore the original portlet URL is instead used. - The submit cache tag generates the necessary JavaScript code for
the onSubmit event in the HTML Form to invoke the above JavaScript
function
functionName
.
Upon a cache hit the next time the same request is detected, the following sequence of events occurs:
- The
provideDynamicContent()
callback method in the DCP object is invoked and generates the following JavaScript code to the beginning of the cached content fragment:<script language="javascript"> var variableName = '/wps/portal/…'; </script>
- When this code snippet is loaded into the user's Web browser
with the cached fragment, it triggers the previously generated JavaScript
to use the portlet URL declared in this new JavaScript variable
variableName
, instead of the one that has been cached.