How to add graph to jsp

Hi!

I want to show several graphs for different projects on my custom page.

I'm new to TeamCity plugins development, so I started from https://confluence.jetbrains.com/display/TCD9/Custom+Statistics

To insert statistics chart into a jsp page:


<%@taglib prefix="stats" tagdir="/WEB-INF/tags/chart"%>

<stats:buildChart id="g1" valueType="BuildDuration"/>


But this is obsolete information for TC9.

Can anybody show a simple example displaying graph? Or any additional info about graphs?

4 comments
Comment actions Permalink

Ok, i can add graph to Statistics tab with SimplePageExtension and:

<stats:buildGraph id="TestGraph" valueType="BuildDuration" />


But how to display it on custom page, provided by BaseController?

package ru.mail.teamcity.plugin.customstats; import jetbrains.buildServer.controllers.BaseController; import jetbrains.buildServer.serverSide.ProjectManager; import jetbrains.buildServer.serverSide.SProject; import jetbrains.buildServer.web.openapi.PluginDescriptor; import jetbrains.buildServer.web.openapi.WebControllerManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.List; public class AppServer extends BaseController {     @NotNull     private static final String PATH_TO_JSP = "Hello.jsp";     @NotNull     private final PluginDescriptor myDescriptor;     @NotNull     private final ProjectManager projectManager;     public AppServer(@NotNull WebControllerManager manager,                      @NotNull PluginDescriptor descriptor,                      @NotNull ProjectManager projectManager) {         this.projectManager = projectManager;         manager.registerController("/customstats.html",this);         myDescriptor = descriptor;     }     @Nullable     @Override     protected ModelAndView doHandle(@NotNull HttpServletRequest httpServletRequest,                                     @NotNull HttpServletResponse httpServletResponse) throws Exception {         final List<SProject> activeProjects = projectManager.getActiveProjects();         final SProject sProject = activeProjects.get(0);         final ModelAndView modelAndView = new ModelAndView(myDescriptor.getPluginResourcesPath(PATH_TO_JSP));         modelAndView.getModel().put("activeProjects", activeProjects);         modelAndView.getModel().put("buildTypes", sProject.getBuildTypes());         return modelAndView;     } }


Hello.jsp:

<%@ page contentType="text/html;charset=UTF-8" language="java" session="true"   %><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"   %><%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"   %><%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"   %><%@taglib prefix="stats" tagdir="/WEB-INF/tags/graph"   %><%@taglib prefix="bs" tagdir="/WEB-INF/tags"   %> <jsp:useBean id="activeProjects" scope="request" type="java.util.List<jetbrains.buildServer.serverSide.SProject>"/> <jsp:useBean id="buildTypes" scope="request" type="java.util.List<jetbrains.buildServer.serverSide.SBuildType>"/> <html> <body>     <select id="project">         <c:forEach var="project" items="${activeProjects}">           <option value="${project.getProjectId()}">               ${project.getName()}           </option>         </c:forEach>     </select>     <select id="buildType">         <c:forEach var="buildType" items="${buildTypes}">           <option value="${buildType.getBuildTypeId()}" qqq="${buildType.getExternalId()}">               ${buildType.getName()}           </option>         </c:forEach>     </select>     <br>     <c:forEach var="buildType" items="${buildTypes}">         <stats:buildGraph id="HelloGraph_${buildType.getExternalId()}"                           valueType="BuildDuration"                           buildTypeExternalId="${buildType.getExternalId()}"                           projectExternalId="${buildType.getProject().getExternalId()}"                           />     </c:forEach> </body> </html>



Unfortunatly page throws NPE in stats:buildGraph.

How to understand whats wrong? Any ideas?

0
Comment actions Permalink

Hi Dmitrii,

The problem is that <buildGraph> requires BuildGraphHelper bean in the model. It isn't in the openapi, however there is a simple way to get it - there is special controller accessible on "/buildGraph.html" which provides the bean. It requires only "jsp" attribute leading to your page. Somewhat like this should work:

 
<bs:page>
  <jsp:attribute name="body_include">

          <!-- The page contents (without html and body tags) -->

  </jsp:attribute>
</bs:page>
0
Comment actions Permalink

Yeap, this documentation is really outdated. We will update it.

0
Comment actions Permalink

Thanks! It works with

final ModelAndView modelAndView = new ModelAndView("/buildGraph.html?jsp=" + myDescriptor.getPluginResourcesPath(PATH_TO_JSP))
0

Please sign in to leave a comment.