There is no community object in Liferay, it's just a different type of group (see GroupConstants )
If you have access to ThemeDisplay object, I think this will give you a community id
long id = themeDisplay.getLayout().getGroupId();
In struts action, you can get ThemeDisplay as follows:
ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
where request can be RenderRequest or ActionRequest .
blank source share