Add Web-Sections to Servlets Implements Web Interface Manager not displaying sections

I am interested to know how to add custom web sections to servlets in confluence. I have been able to successfully create servlets, macros, web sections and web items, however, I do not know how to get the web sections and macros to display on the servlet page.

We’ll probably need more information about what you’re trying to do.

Are you trying to render web-panel module content on your own servlet? In that case - take a look at WebInterfaceManager https://docs.atlassian.com/DAC/javadoc/plugins/2.5/reference/com/atlassian/plugin/web/WebInterfaceManager.html .

If you’re just trying to get the shell around the page - then you’ll want to take a look at the decorators: https://developer.atlassian.com/server/confluence/using-standard-page-decorators/

Hi Daniel,

Sorry I could not reply earlier I was flagged as a robot for typing to fast.

I checked out what you were saying and I have determined I do not have enough information to correctly implement the WebInterfaceManager.

What I have done is tried to implement the interface on the servlet, and wrote the methods to override the interface. This method was unsuccessful but it did not break the plugin. My guess is at this point the servlet does not directly implement the interface but references it from an implementation class. If there are any documents or code that you have that does load a menu using the WebInterfaceManager it would be helpful.

You shouldn’t have to implement any methods. I’ve created a sample plugin at https://bitbucket.org/lagomdaniel/example-webinterfacemanager/src/master/

But basically:


@Scanned
public class MyServlet extends HttpServlet{
    private static final Logger log = LoggerFactory.getLogger(MyServlet.class);

    @ComponentImport
    private final WebInterfaceManager webInterfaceManager;

    @Inject
    private MyServlet( final WebInterfaceManager webInterfaceManager)
    {
        this.webInterfaceManager = webInterfaceManager;
    }


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        resp.setContentType("text/html");


        Map<String, Object> context = new HashMap<>();

        resp.getWriter().write("<html><body>");
        for(WebPanel webPanel: this.webInterfaceManager.getWebPanels("my-location"))
        {
            resp.getWriter().write("<hr/>");

            resp.getWriter().write( webPanel.getHtml(context));
            resp.getWriter().write("<hr/>");
        }

        resp.getWriter().write("</body></html>");
    }

}

Note the @ComponentImport on the WebInterfaceManager which is then injected to the constructor. Once you have that - you can just call the getWebPanels method on it. The String passed in is the location that you’d want to use.

1 Like