Develop > Presentation layer > WebSphere Commerce integration with WebSphere Portal > WebSphere Commerce Portal caching


Enable 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

  1. At the top of the portlet JSP file, declare the new cache tag library using cache as the prefix.

  2. For all portlet action URLs that use the GET method, substitute all occurrences of <portlet:actionURL> with <cache:actionURL>.

  3. For all portlet render URLs, substitute all occurrences of <portlet:renderURL> with <cache:renderURL>.

  4. 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.

  5. 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:

  1. The portlet JSP file is compiled into byte code.

  2. 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.

  3. 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:

    function functionName(f) {
        if (typeof(variableName) == 'undefined') {
            f.action = "/wps/portal/…";     } else {
            f.action = variableName;     }
        f.submit(); }
    

    Where 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 JavaScript variableName is not yet defined and therefore the original portlet URL is instead used.

  4. 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:

  1. 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>
    

  2. 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.


+

Search Tips   |   Advanced Search