Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Raja Seth
Delete profile image in custom portlet
April 24, 2013 7:04 AM
Answer

Raja Seth

Rank: Regular Member

Posts: 122

Join Date: August 18, 2011

Recent Posts

Hi All,

In my project I am developing user account portlet, somewhat similar to My Account in Liferay control panel. I have used image upload functionality using the below taglib :

<liferay-ui:logo-selector
defaultLogoURL="/my-new-theme/images/img_comment_user.png"
editLogoURL="${editPortraitURL}"
imageId="<%= userProfile.getPortraitId() %>"
logoDisplaySelector=".user-logo"
showBackground="<%= false %>" />


When I uploads the image, it gets uploaded and saved for the user logged in. But for deleting the image, as from control panel we need to save our modifications, similar kind of functionality I want to use on save.

Please let me know if anyone have developed the same thing in custom portlet.

Any help would be appreciated.

Thanks,
Raja
Apoorva Prakash
RE: Delete profile image in custom portlet
April 25, 2013 5:37 AM
Answer

Apoorva Prakash

Rank: Liferay Master

Posts: 659

Join Date: June 15, 2010

Recent Posts

Raja Seth:
Hi All,

In my project I am developing user account portlet, somewhat similar to My Account in Liferay control panel. I have used image upload functionality using the below taglib :

<liferay-ui:logo-selector
defaultLogoURL="/my-new-theme/images/img_comment_user.png"
editLogoURL="${editPortraitURL}"
imageId="<%= userProfile.getPortraitId() %>"
logoDisplaySelector=".user-logo"
showBackground="<%= false %>" />


When I uploads the image, it gets uploaded and saved for the user logged in. But for deleting the image, as from control panel we need to save our modifications, similar kind of functionality I want to use on save.

Please let me know if anyone have developed the same thing in custom portlet.

Any help would be appreciated.

Thanks,
Raja


Hello Raja,

Method is already available in API, see the following:

1com.liferay.portal.service.UserLocalServiceUtil.deletePortrait(userId)


HTH.

Thanks and Regards,
Apooorva Prakash
Raja Seth
RE: Delete profile image in custom portlet
April 26, 2013 7:39 AM
Answer

Raja Seth

Rank: Regular Member

Posts: 122

Join Date: August 18, 2011

Recent Posts

Hi Apoorva,

Thanks for your reply. Yes I am aware about this method, but using liferay taglib, I am not able to delete it.

Also, using this method only entry from USER table gets removed not from IMAGE table. But if you check the flow from control panel, it removes from both the places. Correct me if I am wrong!

Please let me know how we can delete the image from taglib.

Thanks,
Raja
Chintan Akhani
RE: Delete profile image in custom portlet
April 26, 2013 7:46 AM
Answer

Chintan Akhani

Rank: Regular Member

Posts: 111

Join Date: March 13, 2008

Recent Posts

Hi Raja,

"deletePortrait(long userId)" this method will take care of image deletion from Image gallery as well. If you check the implementation of this method in UserLocalServiceImpl than you will find two calls, one is for 'update user' and another one is 'delete image'. So this method should work for you. Please check your logs as well.

Thanks,
Chintan
Raja Seth
RE: Delete profile image in custom portlet
May 2, 2013 5:11 AM
Answer

Raja Seth

Rank: Regular Member

Posts: 122

Join Date: August 18, 2011

Recent Posts

Hi Chintan,

Thanks for your reply. I used this method in my controller :

boolean deleteLogo = ParamUtil.getBoolean(request, "deleteLogo");
if (deleteLogo) {
UserServiceUtil.deletePortrait(user.getUserId());
}


But something strange is happening. When I delete and click on save button from my custom portlet, my profile image is replaced by the liferay logo image. I debugged and found out, My Account in Liferay control panel also calls the same method. Also when I looked into the database, the call from my custom portlet only removes the entry from IMAGE_ table, but doesn't reset's the PORTRAITID in USER_ table. Because of which its displaying the liferay logo image.

Please help me out.

Thanks,
Raja