How to Create a View Controller

Viewpoint
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 Create a View Controller

 Here is the process for implementing a class that renders a page:

  1. Create a new java class that implements the com.teradata.portlets.mvc.Controller interface.
  2. Create a method in your new class. The name of the method should match the name of the page (e.g., "summary").
  3. Create a bean definition for the controller class in your portlet configuration file.
  4. Map incoming requests to your controller class in your portlet configuration file.
  5. (Optional) If your controller will be responding to servlet requests in addition to portlet requests, then repeat the last two steps for your servlet configuration files.

Here is an example of a controller with a method that will respond to requests for the summary page.

public class SkewedSessionsViewController extends ViewpointControllerBase
{
public void summary(ControllerContext ctx)
{
// set 'summary.jsp' as the view for this page.
ctx.setViewName("summary");

// get the user's preferences for this portlet instance
SkewedSessionsPreferences preferences = new SkewedSessionsPreferences();
preferences = ctx.loadPreferences("skewedSessions", preferences);

// pass the preferences to the view
ctx.addViewObject("preferences", preferences);

// the 'context' is a unique identifier for the instance of this portlet.
ctx.addViewObject("context", getContext());
}
}

Your Teradata Viewpoint controller class can implement more than one controller method per class. So if you have a summary page and a detail page, you would create a summary method (as illustrated above) and another method named detail that collects the data needed by the detail view.

Here is a portlet configuration file that maps the controller in the example above to portlet VIEW mode requests:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

<!-- view resolvers -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="order"><value>1</value></property>
<propertyname="viewClass">
<value>org.springframework.web.servlet.view.JstlView</value>
</property>
<property name="prefix"><value>/WEB-INF/portlet-jsp/</value></property>
<property name="suffix"><value>.jsp</value></property>
</bean>

<!-- Handler Mappings -->

<bean id="portletModeHandlerMapping"
class="org.springframework.web.portlet.handler.PortletModeHandlerMapping"
abstract="false" singleton="true" lazy-init="default" autowire="default"
dependency-check="default">
<description>Maps request paths to controllers that handle the request</description>
<property name="order" value="2"/>
<property name="portletModeMap">
<map>
<entry key="view">
<ref bean="skewedSessionsViewController"/>
</entry>
</map>
</property>
</bean>

If your controller responds to servlet requests, then you also need to configure the controller in your servlet configuration file. Here is an example that maps incoming requests with the URL that ends in /summary to the controller in the example above:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

<!-- Handler Mappings -->
<!-- map requests to controllers by mapping url to the controller name -->
<bean id="servletHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/summary">skewedSessionsViewController</prop>
</props>
</property>
</bean>

<!-- view resolvers -->
<bean id="servletViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<description>Resolves view names to JSP implementations in the portlet-jsp directory</description>
<property name="order"><value>1</value></property>
<property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property>
<property name="prefix"><value>/WEB-INF/portlet-jsp/</value></property>
<property name="suffix"><value>.jsp</value></property>
</bean>

</beans>