Remove Preference on Webtop Browser Close (onUnload)

fainemr
edited August 21, 2017 in Documentum #1

We have a requirement that a warning banner be displayed once per session.  I've implemented the warning banner as text on a custom Kerberos Docbase selection page.  I can clear the preference  "application.authentication.docbase" when the user uses the Logout button and I'd like to also do the same when the browser is closed.  I believe this will have to also be when the user navigates away from the application.  That's not a specific requirement but it's okay.

So now, I've tried to use the onUnload method in the mainex component to do a post server event to my class event method onUnload, which will then remove the preference from the preference store  (write it as an empty string).   This approach works for the logout component but in the main component, I cannot get the server event to post.   Any assistance or suggestions are appreciated.

Currently, I'm attempting to use the onUnload method of the frame in classic.jsp to post the server event but it is not working either:

Custom Classic class.


package gov.nasa.msfc.repository.classic;

import com.documentum.fc.common.DfLogger;
import com.documentum.web.formext.config.IPreferenceStore;
import com.documentum.web.formext.config.PreferenceService;
import com.documentum.webtop.webcomponent.classic.Classic;
public class CustomClassic extends Classic {

/**
* Default serialization id
*/
private static final long serialVersionUID = 1L;

/**
* onUnload - Clear the cookie that selects the docbase when the page is unloaded
* @return void
*/
public void onUnload() {
DfLogger.debug(this, "Removing \"application.authentication.docbase\" preference", null, null);
IPreferenceStore preferenceStore = PreferenceService.getPreferenceStore();
preferenceStore.writeString("application.authentication.docbase", "");
}
   
}

Custom mainex_component.xml


<config>
<scope version="5.3">
<component modifies="main:webtop/config/mainex_component.xml">
<replace path="pages">
<pages>
<start>/custom/main/mainex.jsp</start>
<classic>/custom/main/mainex.jsp</classic>
<streamline>/custom/main/mainex.jsp</streamline>
</pages>
</replace>
</component>
</scope>
</config>

Custom mainex.jsp


<%
//
%>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page errorPage="/wdk/errorhandler.jsp" %>
<%@ taglib uri="/WEB-INF/tlds/dmform_1_0.tld" prefix="dmf" %>
<%@ page import="com.documentum.web.form.Form" %>
<%@ page import="com.documentum.webtop.webcomponent.main.Main" %>
<%@ page import="gov.nasa.msfc.repository.classic.CustomClassic" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<dmf:webform/>
<title><dmf:label nlsid="MSG_TITLE"/></title>
<script type='text/javascript' src='<%=Form.makeUrl(request, "/webtop/main/main.js")%>'></script>
<script type='text/javascript' src='<%=Form.makeUrl(request, "/wdk/include/timeoutControl.js")%>'></script>
<script type='text/javascript' src='<%=Form.makeUrl(request, "/wdk/include/unsavedChanges.js")%>'></script>
<script type='text/javascript'>onSetView("classic");</script>
<script type='text/javascript'>
function onUnload()
{
promptIfUnsavedChangesExist();
manageTimeout(frames["timeoutcontrol"]);
}
</script>
</head>
<%
Main main = (Main)pageContext.getAttribute(Form.FORM, PageContext.REQUEST_SCOPE);
String strClassicArgs = "";
StringBuffer classicArgsBuffer = new StringBuffer();
String strEntrySection = main.getEntrySection();
String strEntryId = main.getEntryId();
boolean haveEntrySection = strEntrySection != null && strEntrySection.length() > 0;
boolean haveEntryId = strEntryId != null && strEntryId.length() > 0;
if (haveEntrySection || haveEntryId)
{
classicArgsBuffer.append("?");
if (haveEntrySection)
{
classicArgsBuffer.append(CustomClassic.ARG_ENTRY_NODE);
classicArgsBuffer.append('=');
classicArgsBuffer.append(strEntrySection);
if (haveEntryId)
{
classicArgsBuffer.append('&');
}
}
if (haveEntryId)
{
classicArgsBuffer.append(CustomClassic.ARG_ENTRY_ID);
classicArgsBuffer.append('=');
classicArgsBuffer.append(strEntryId);
}
strClassicArgs = classicArgsBuffer.toString();
}
//
%>
<dmf:frameset rows='0,0,28,*,21' border='0' framespacing='0' frameborder='false' onunload='onUnload()'>
<dmf:frame name="timeoutcontrol" src="/wdk/timeoutcontrol.jsp" marginwidth="0" marginheight="0" scrolling="no" noresize="true"/>
<dmf:frame name="residentucfinvoker" src="/component/residentucfinvoker" marginwidth="0" marginheight="0" scrolling="no" noresize="true"/>
<dmf:frame nlsid="MSG_TITLEBAR" name='titlebar' src="/component/titlebar" scrolling="no" noresize="true"/>
<dmf:frame nlsid="MSG_CLASSICVIEW" name='view' src='<%="/custom/classic/classic.jsp" + strClassicArgs%>' scrolling="no" noresize="true"/>
<dmf:frame nlsid="MSG_MESSAGEBAR" frameborder='false' name='messagebar' src='/component/messagebar' scrolling='no' noresize="true"/>
</dmf:frameset>
</html>

Custom classic.jsp


<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page errorPage="/wdk/errorhandler.jsp" %>
<%@ taglib uri="/WEB-INF/tlds/dmform_1_0.tld" prefix="dmf" %>
<%@ page import="com.documentum.web.form.Form" %>
<%@ page import="gov.nasa.msfc.repository.classic.CustomClassic" %>
<%@ page import="com.documentum.webtop.webcomponent.browsertree.BrowserTree" %>
<%@ page import="com.documentum.web.common.AccessibilityService" %>
<%@ page import="com.documentum.web.common.LocaleService"%>
<html>
<head>
<dmf:webform formclass="gov.nasa.msfc.repository.classic.CustomClassic"
nlsbundle="com.documentum.webtop.accessibility.FrameTitleNlsProp" />
<script type="text/javascript" src='<%=Form.makeUrl(request, "/wdk/include/dynamicAction.js")%>'></script>
<script type="text/javascript" src='<%=Form.makeUrl(request, "/webtop/classic/browsertree/browsertree.js")%>'></script>
<script type="text/javascript" src='<%=Form.makeUrl(request, "/webtop/classic/classic.js")%>'></script>
<script type="text/javascript">
function onUnload()
{
Trace.println("onUnload Executed!");
<!-- execute onUnload class event handler -->
<dmf:postserverevent handlermethod="onUnload"/>
<!-- onPageUnload in classic.js doesn't execute, so we wrap it here -->
unregisterActionControls();
}
</script>


</head>
<%
CustomClassic form = (CustomClassic)pageContext.getAttribute(CustomClassic.FORM, PageContext.REQUEST_SCOPE);
String strBrowsertreeArgs = "?inlineRefresh=true";
StringBuffer browsertreeArgsBuffer = new StringBuffer(strBrowsertreeArgs);
String strEntryNode = form.getEntryNode();
// from the request.  We can't get the parameter from the initialization parameters since F5 refresh support
String strEntryObjectId = form.getPageContext().getRequest().getParameter(CustomClassic.ARG_ENTRY_ID);
boolean haveEntryNode = strEntryNode != null && strEntryNode.length() > 0;
boolean haveObjectId = strEntryObjectId != null && strEntryObjectId.length() > 0;
if (haveEntryNode || haveObjectId)
{
if (haveEntryNode)
{
browsertreeArgsBuffer.append("&");
browsertreeArgsBuffer.append(BrowserTree.ARG_ENTRY_NODE);
browsertreeArgsBuffer.append('=');
browsertreeArgsBuffer.append(strEntryNode);
}
if (haveObjectId)
{
browsertreeArgsBuffer.append("&");
browsertreeArgsBuffer.append(BrowserTree.ARG_ENTRY_OBJECT_ID);
browsertreeArgsBuffer.append('=');
browsertreeArgsBuffer.append(strEntryObjectId);
}
strBrowsertreeArgs = browsertreeArgsBuffer.toString();
}
boolean bAccessibilitiesEnabled = AccessibilityService.isAllAccessibilitiesEnabled();
String strRows = "0,*";
if (bAccessibilitiesEnabled)
{
strRows = "100%";
}
//
%>
<dmf:frameset rows="<%=strRows%>" border="0" frameborder="0" framespacing="0" onunload="onUnload()">
<%
if (!bAccessibilitiesEnabled)
{
%>       <dmf:frame nlsid="MSG_TOOLBAR" name='toolbar' marginwidth='0' marginheight='0' frameborder='no' src='/component/toolbar' scrolling='no' noresize="true"/>
<%    }
//
%>
<%
boolean bRtlEnabled = LocaleService.isRightToLeftLocale();
if (bRtlEnabled == true)
{
//
%>
<dmf:frameset cols="*,240" border="3" frameborder="1" framespacing="3">
<dmf:frame nlsid="MSG_WORKAREA" name='workarea' src='/webtop/classic/workarea.jsp' frameborder='0'/>
<dmf:frame nlsid="MSG_BROWSER" name='browser' src='<%="/component/browsertree" + strBrowsertreeArgs%>' frameborder='1' scrolling='auto'/>
</dmf:frameset>
<%
}
else
{
//
%>
<dmf:frameset cols="240,*" border="3" frameborder="1" framespacing="3">
<dmf:frame nlsid="MSG_BROWSER" name='browser' src='<%="/component/browsertree" + strBrowsertreeArgs%>' frameborder='1' scrolling='auto'/>
<dmf:frame nlsid="MSG_WORKAREA" name='workarea' src='/webtop/classic/workarea.jsp' frameborder='0'/>
</dmf:frameset>
<% } %>
</dmf:frameset>
</html>
Tagged:

Comments

  • fainemr
    edited August 21, 2017 #2

    I think I found an easier way to do what I need, though I still think there is probably a best practice way of executing code on exit that I'd still like to learn, so that I may use it for future requirements.


    package gov.nasa.msfc.repository.login;


    import com.documentum.fc.common.DfLogger;
    import com.documentum.web.form.common.CookieManager;
    import com.documentum.web.formext.config.IPreferenceStore;
    import com.documentum.web.formext.config.PreferenceService;
    import com.documentum.web.formext.session.KerberosSSOLogin;


    public class CustomKerberosSSOLogin extends KerberosSSOLogin {


    /**
    * Default serialization ID
    */
    private static final long serialVersionUID = 1L;


    /**
    * The docbase preference
    */
    private static final String DOCBASE_PREFERENCE = "application.authentication.docbase";


    @Override
    protected void writePreferences() {
    DfLogger.debug(this, "Writing Preferences...", null, null);
    super.writePreferences();
    DfLogger.debug(this, "Clearing \"{0}\" preference", new String[] { DOCBASE_PREFERENCE }, null);
    IPreferenceStore preferenceStore = PreferenceService.getPreferenceStore();
    preferenceStore.writeString(DOCBASE_PREFERENCE, "");
    CookieManager.getCookieJar().setSessionCookie(DOCBASE_PREFERENCE, "");
    DfLogger.debug(this, "New value for \"{0}\" is \"{1}\"",
    new String[] { DOCBASE_PREFERENCE, preferenceStore.readString(DOCBASE_PREFERENCE) }, null);
    }


    }