How do I get the current SitePage tool and / or its Properties?

With the help ToolManager

I can get the current placement, context and of course the site through SiteService

. But I want to get the current SitePage properties that the user is currently accessing.

This doubt can be expanded to the current properties of the tool with a little more attention, given that once I have the Tool, I could not find any methods covering its properties.

I could get the properties of the tool, and I use it (this is an instance) through Properties

that obtained with sitepage.getTool(TOOLID).getConfig()

. To save a property, I take the approach ToolConfiguration

and save the data after editing with the method ToolConfiguration.save()

. Is this the correct approach?

+3


source to share


1 answer


You can do this by getting the current session of the tool and then working your way back. Here is the method to do it.

public SitePage findCurrentPage() {
  SitePage sp = null;
  ToolSession ts = SessionManager.getCurrentToolSession();
  if (ts != null) {
    ToolConfiguration tool = SiteService.findTool(ts.getPlacementId());
    if (tool != null) {
      String sitePageId = tool.getPageId();
      sp = s.getPage(sitePageId);
    }
  }
  return sp;
}

      

Alternatively, you can use the current tool to work with it, but I think this method is more complicated.



String toolId = toolManager.getCurrentTool().getId();
String context = toolManager.getCurrentPlacement().getContext();
Site s = siteService.getSite( context );
ToolConfiguration tc = s.getTool(toolId);
String sitePageId = tc.getPageId();
SitePage sp = s.getPage(sitePageId);

      

NOTE . I have not tested this code to make sure it works.

+4


source







All Articles