0
votes

i have liferay 6.2 GA4.. i have a question

i want to use liferay's user portrait change, but i dont want to copy all the code to my portlet...

is there a way to call liferay's portrait update from my portlet? just like in a render URL or something like that... call the edit_user_portrait struts action from liferay's my account portlet, and then let liferay do everything else... update the image, show errors, etc...

using this for example: (this is the code in liferay's my account portlet, to call the pop up that updates the portrait)

<portlet:renderURL var="editUserPortraitURL" windowState="<%= LiferayWindowState.POP_UP.toString() %>">
      <portlet:param name="struts_action" value="/users_admin/edit_user_portrait" />
      <portlet:param name="redirect" value="<%= currentURL %>" />
      <portlet:param name="p_u_i_d" value="<%= String.valueOf(selUser.getUserId()) %>" />
      <portlet:param name="portrait_id" value="<%= String.valueOf(selUser.getPortraitId()) %>" />

i want something like this, but this is not working... where i tell the portlet name (users admin in this case) where the struts action lives... and let liferay handle the rest..

<liferay-portlet:renderURL portletName="<%=PortletKeys.USERS_ADMIN %>" var="editUserPortraitURL" windowState="<%= LiferayWindowState.POP_UP.toString() %>">
    <portlet:param name="struts_action" value="/users_admin/edit_user_portrait" />
    <portlet:param name="redirect" value="<%= currentURL %>" />
<portlet:param name="p_u_i_d" value="<%= String.valueOf(selUser.getUserId()) %>" />
<portlet:param name="portrait_id" value="<%= String.valueOf(selUser.getPortraitId()) %>" />

for this i imported the <%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet"%>

this code gives me a permissions error:

You do not have the roles required to access this portlet.

but i doesnt send any error in the log.. how can i make this work? what im i missing?

thank you!!

2
Are you providing this feature of portrait udpate to users?Parkash Kumar
yes, but in a custom portlet...juanmeza
Hi, have tried what u have said above but it never worked dont know the exact reason, whtat i did was used the below URL <%=themeDisplay.getPortalURL()%>/group/control_panel/manage?p_p_id=2&p_p_lifecycle=0&p_p_state=pop_up&p_p_mode=view&_2_portrait_id=0&_2_p_u_i_d=<%=themeDisplay.getUserId()%>&_2_struts_action=%2Fmy_account%2Fedit_user_portrait and it worked for meSaleem Khan
it does work using the url!... thank you Saleem!!juanmeza

2 Answers

1
votes

i want to use liferay's user portrait change

Using Liferay API you can do this.

InputStream inputStream = new FileInputStream(file);
byte[] bytes = FileUtil.getBytes(inputStream);
UserServiceUtil.updatePortrait(themeDisplay.getUser().getUserId(), bytes);

reference

Thanks.

1
votes

What I ended up doing is what Saleem suggested in the comments:

<%String editPortraitUrl = themeDisplay.getPortalURL()+"/group/control_panel/manage?p_p_id=2&p_p_lifecy‌​cle=0&p_p_state=pop_up&p_p_mode=view&_2_portrait_id=0&_2_p_u_i_d="+themeDisplay.getUserId()+"&_2_struts_action=%2Fmy_account%2Fedit_user_portrait";
%>
<liferay-ui:logo-selector
currentLogoURL="<%= selUser.getPortraitURL(themeDisplay) %>"
defaultLogoURL="<%= UserConstants.getPortraitURL(themeDisplay.getPathImage(), selUser.isMale(), 0)     %>"
editLogoURL="<%=editPortraitUrl %>"
imageId="<%= selUser.getPortraitId() %>"
logoDisplaySelector=".user-logo"/>

Here is a link for reference: https://www.liferay.com/es/community/forums/-/message_boards/message/57413369