Simpler Inline Editing In IWWCM
By Adrian Sutton
IWWCM has a component specifically to provide “inline editing” – in other words, adding links to content items so you can quickly edit, accept, reject or delete if you’re logged in as a user who has permission to do such things. I have two problems with this approach:
- You have to be logged in to see the links.
- The links affect the way the page looks so you don’t see the site the same way as normal visitors.
Within a portal environment or even an intranet, neither of those problems really apply, but when you’re publishing out a public website they can be an issue.
Fortunately, there’s nothing particularly special about the authoring component that provides these functions – it’s just a thin veneer over IWWCM remote access, which in turn is really just a defined set of URLs that you call to get stuff to happen. Thus, you can implement your own inline editing solution by generating those URLs wherever you want them.
The tricky part is that the URLs have to include the document ID which is only available via WCM tags within an authoring component. With a little bit of custom code using the WCM API you can find the right ID and generate the URL you need:
<%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="javax.servlet.*" %> <%@ page import="com.ibm.workplace.wcm.api.*" %> <%@ page import="com.ibm.workplace.wcm.api.exceptions.*" %> <%! String getContentId(String path) { try { Workspace ws = WCM_API.getRepository().getAnonymousWorkspace(); path = path.substring(1); int delimEntry = path.indexOf("/"); String libName = path.substring(, delimEntry); ws.setCurrentDocumentLibrary(ws.getDocumentLibrary(libName)); DocumentIdIterator contentIdIterator = ws.findContentByPath(path); if (contentIdIterator.hasNext()) { return contentIdIterator.next().toString(); } } catch (Throwable t) { t.printStackTrace(); } return ""; } %> <script type="text/javascript"> function doKeyDown(event) { if (event.ctrlKey==1 && event.altKey==1 && event.keyCode==69) { window.open( "/wps/myportal/wcmAuthoring?wcmAuthoringAction=edit&docid=<%= getContentId(request.getPathInfo()) %>", "lwedit"); } } </script>
Now you have a magical bit of JavaScript that will popup the edit window whenever you type control-alt-E. If you’re not logged in it will prompt you to authenticate first, then take you to the edit page.
PS: The code is rubbish, but it proves out the idea nicely.