// register portlet and update Hashmap
public String registerportlet(String tmlDb, String tmlCode, String title) throws WGAPIException {
WGPortlet newPortlet = profile.getprofile().getPortletRegistry().createPortlet(tag.tmlContext.getmaincontext().db().getDbReference(), reg);
newPortlet.setDesignDb(tmlDb);
newPortlet.setDesign(tmlCode);
newPortlet.setName(title);
profile.getprofile().getPortletRegistry().insertPortlet(newPortlet);
TMLPortlet newTMLPortlet = new TMLPortlet(tag, profile, newPortlet);
// Fetch portlet session context (so the following init event will not be overridden)
newTMLPortlet.getSessionContext();
// Add portlet init event
PortletEvent event = new PortletEvent("init");
event.setSource(newPortlet.getKey());
event.setSourceName(title);
event.setTargetPortletKey(newPortlet.getKey());
addEventToQueue(event, tag.tmlContext.gethttpsession());
return newPortlet.getKey();
}