How to Give Your View a Namespace

Teradata Viewpoint is Teradata's strategic and innovative SOV (single operational view) for Teradata DB, Aster, and HDP Hadoop systems management and monitoring that enables Teradata's Unified Data Architecture (UDA).
Teradata Employee

How to Give Your View a Namespace

Namespacing a portlet view is very important because it prevents the unintended interaction of multiple portlets on the same page. This can easily happen if multiple HTML elements on the page have the same ID name or JavaScript variables have the same name due to closures. The safest way to prevent these interactions is to assign a namespace to all of the elements of your view that have the potential for conflict with other elements.

Retrieving the Namespace

Any view that is created for a portlet should have a namespace so there are no conflicts. The namespace for a portlet is retrieved and attached to the view on the server side in the controller automatically if either the ViewpointControllerBase or theViewpointFormControllerBase class is extended. The getContext() function of both these controllers retrieves the unique namespace string if you need to use the namespace on the server side:

import com.teradata.portlets.mvc.ViewpointControllerBase;

* MyTestClass declaration
public class MyTestClass extends ViewpointControllerBase
* myViewName function declaration
public void myViewName()
// Get the namespace from the controller
String myNamespace = getContext();
// Do something with the namespace

Giving the View a Namespace

 To use the namespace in your view page, you specify it using the normal JSP variable display method:

<%@ page contentType="text/html" language="java" %>

<!-- My namespaced div id -->
<div id="helloDiv${context}">
My namespace is: ${context}

<script type="text/javascript">
// My namespaced JavaScript variable
var myVar${context} = 'xyz_${context}';

// My namespaced JavaScript function
function myJavascript${context}()
alert('My namespace with \"xyz_\" perpended is: ' + myVar${context});

// Call my namespaced JavaScript function

Providing a Namespace for Important Elements

 There are a number of elements that should always have a namespace due to the high probability of conflict:

  • HTML element IDs that are searched for in the DOM through JavaScript or jQuery. The behavior of DOM searching varies based upon the browser used, so searching for a generalized ID that occurs multiple times might return different elements in different browsers
  • JavaScript functions and variables specific to a portlet. The Teradata Viewpoint portal depends heavily on JavaScript. It is very plausible that an underlying Teradata Viewpoint variable or function could be overwritten or overloaded if elements are not given a proper namespace.
Tags (3)