ExternalContext externalContext = facesContext.getExternalContext();
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
String portalURL = themeDisplay.getPortalURL();
String imagePath = portalURL + "/image";
UserPortraitResource userPortraitResource = new UserPortraitResource(imagePath, selectedUser,
uploadedFileId);
String requestPath = userPortraitResource.getRequestPath();
Application application = facesContext.getApplication();
ViewHandler viewHandler = application.getViewHandler();
String resourceURL = viewHandler.getResourceURL(facesContext, requestPath);
selectedUserPortraitURL = externalContext.encodeResourceURL(resourceURL);
}