An on Edit Content

Embed Size (px)

DESCRIPTION

WCM

Citation preview

Introduction

There are cases when Anonymous Users should be able to update WCM content, or more specifically parts of content.

For this example, assume a Comments section on a piece of content. The idea is that anonymous users can view the content, and use an html form to add their personal comments about the piece of content. The example here is that the content pertains to a product, but this could be anything.

The content when rendered will have a place for a form so that end users can add to the existing comments section:

Important WCM Content pieces

There are several ways that this can be done, including using a JSP component on the content itself, so that the form submits to itself. For simplicity, however, I have separated the content from the JSP that processes the request.

There are 2 separate content concepts being used:

1) The content thats being updated

2) A helper content object that processes the JSP thats used to update the content.

For the helper content object, I did the following:

1) Create a WCM Authoring template that has one JSP component, named JSPComp

2) Create a WCM Presentation Template with the following tag

3) Create a site area that maps the authoring template to the presentation template

4) Create a piece of content that holds the necessary JSP. Populated the JSP component with the following path:/jsp/html/updateReviewWork.jsp

The JSP code for updateReviewWork.jsp is detailed below. In for this example, the content I created exists at the following path:

/mycointernetdesign/APITools/APIToolsSiteArea/updateReviewWork.jsp

Where mycointernetdesign is the library, APITools/APIToolsSiteArea the site/site area path, and updateReviewWork.jsp is the name of the content

In the content thats being updated, in order to provide the functionality, I did the following:

1) Edited the Authoring Template for the content, and added a JSP component named JSPComp. In the Authoring Template directly, populated this with the path /jsp/html/updateProductReviews.jsp. The code for the updateProductReviews.jsp JSP will be given later.

2) Applied the authoring template to all the content

3) Updated the presentation template with an

4) The end result is that when the content is rendered, the JSP component jsp will be rendered as well.

Code for updateProductReviews.jsp

The updateProductReviews.jsp is very simple. All it does is create an HTML form to capture user input. The only reason a JSP is even used is to retrieve the path to the current content, which we can do using the WCM API

Enter your review:

Name:

Everything is pretty straightforward, the trick is here:

This code retrieves the path to the specific content thats being rendered.

This code:

Is basically creating the form action so that the local rendering portlet on the page will be updated to point to the updateReviewWork.jsp content, which is holding a JSP. That JSP is looking for a path parameter to retrieve the sepcific content it needs to update. That path parameter will be pointing to the content that is right now being rendered.

Code for updateReviewWork.jsp

The code for processing the request is just as follows:

At a high level, what happens is:

1) Path is retrieved from the request object

2) System workspace is created

3) Content by the path is retrieved.

4) The component to update is retrieved from the content, and the newly passed comment information is appended to the current value

5) The component is pushed back on the content, and the content is saved.

Note, the meta-equiv code essentially redirects the request back to the content that was being rendered. In my example, thats on a specific WP page, but thats not important.