Programmer : Mashup Programmer : Customizing the Mashup UI : Creating Controllers
 
Creating Controllers
 
Create and package a controller
Reference JSP in a controller
You can create custom Spring Controllers to add server side logic to the application.
Create and package a controller
Reference JSP in a controller
Create and package a controller
Create a controller
You must respect the following requirements:
Your class must be in a subpackage of package: com.exalead.cv360.searchui.view.widgets.controller. For example: com.exalead.cv360.searchui.view.widgets.controller.hello
There must be an @CustomComponent annotation.
The Spring Controller is a class annotated with the @Controller annotation.
Example of an "Hello World" controller:
package com.exalead.cv360.searchui.view.widgets.controller;
@CustomComponent(displayName="Hello World")
@Controller
public class HelloWorldController {
@RequestMapping(value = "/helloWorld", method = { RequestMethod.GET })
public void helloWorld(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.getWriter().print("Hello World!!");
}
}
This Controller can then be reached at: http://<HOSTNAME>:<BASEPORT>/<context-name>/helloWorld
Package the controller in a custom Plugin
The Exalead CloudView Eclipse plugin must be installed.
1. From the Package Explorer panel, right-click on the Controller class and select CloudView Mashup > Export to file.
2. In the Mashup > Export plugin window, specify the name and destination of the plugin and click Finish.
3. The plugin is packaged as .zip file and can be uploaded in Mashup Builder, in Application > Manage components > Plugins.
4. Restart the search server.
a. Go to Application > Developer area.
b. Click Reload components
c. Select the Restart search server processes option.
5. Go to Application > Manage components > Controllers.
The new controller should be added to the list of controllers.
Package your controller manually in a jar
You can also package your controller manually in a jar but we strongly recommend to package your controller as a plugin.
1. Right-click the controller class and select Export...
2. In the Select window, expand the Java node and select JAR file.
3. Click Next and in the Jar File Specification window:
a. From Select the resources to export, select the class file to export.
b. From Select the export destination, select where you want to export the JAR file.
c. Select the Add directory entries option.
d. Click Finish.
4. Copy the exported jar in your <DATADIR>/webapps/360-mashup-ui/WEB-INF/lib/ folder.
5. Open Mashup Builder and restart the search server.
a. Go to Application > Developer area.
b. Click Reload components.
c. Select the Restart search server processes option.
6. In your browser, open the mashup-ui page, for example, http://myhost:10000/mashup-ui/helloWorld.
The page should display Hello World!!
Reference JSP in a controller
Follow the procedure below to reference JSP in a controller
1. Copy your JSP somewhere within the following directory: <DATADIR>/webapps/360-mashup-ui/WEB-INF/jsp/
2. Edit the following file: <DATADIR>/webapps/360-mashup-ui/WEB-INF/tiles-def.xml
3. Add a line within <tiles-definitions>, for example: <definition name="mytemplate" template="/WEB-INF/jsp/path/of/the/jsp/page.jsp" />
4. Create and package a custom controller and deploy it as a plugin, for example:
package com.exalead.cv360.searchui.view.widgets.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class TestController {
@RequestMapping(value = "/test", method = { RequestMethod.GET, RequestMethod.POST })
public String test(HttpServletRequest request, HttpServletResponse response) {
return "mytemplate";
}
}
5. Restart the search server.
Your page should be accessible at the following URL: http://<HOSTNAME>:<PORT>/mashup-ui/test Where:
mashup-ui is the context path of the application deployed by jetty.
/test is the path specified by the @RequestMapping annotation.
Note: The default controller renders pages as /page/pageName, for example, http://<HOSTNAME>:<PORT>/mashup-ui/page/search and is written as follows:
@RequestMapping(value = "/page/{pageName}", method = RequestMethod.GET)
public String renderPage(HttpServletRequest request, HttpServletResponse response, @PathVariable
(“pageName”) String pageName) throws Exception {
}