Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Aryan sds
Add profile image to liferay user using jsf 2.0
22. April 2013 03:24
Antwort

Aryan sds

Rang: Junior Member

Nachrichten: 57

Eintrittsdatum: 24. April 2012

Neue Beiträge

I am trying add profile image to liferay user using jsf portlet with primefaces p:fileUpload component.

Now as we know to add profile image to user we use

1  UserLocalServiceUtil.updatePortrait(user, bytes_file);




where user is userid and bytes_file is array of bytes

to get value of bytes_file liferay use this way.


1 UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
2   
3    File file=uploadRequest.getFile(fileName);
4   
5    i.e byte[] bytes=FileUtil.getBytes(file);


But as I am using jsf portlet , unable to get actionrequest object, so how can I get actionrequest object ?

I have also tried to get actionrequest using this ways.
1   
2    FacesContext facesContext = FacesContext.getCurrentInstance();
3    ExternalContext externalContext = facesContext.getExternalContext();
4    ActionRequest actionRequest = (ActionRequest) externalContext.getRequest();


or

1 LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
2    ActionRequest actionRequest = (ActionRequest) liferayFacesContext.getPortletRequest();


but it's giving me errors as com.liferay.portlet.ResourceRequestImpl
cannot be cast to javax.portlet.ActionRequest


I have also tried in this way ....

1    step 1.  byte[] bytes_file = event.getFile().getFileName().getBytes();
2    step 2.   UserLocalServiceUtil.updatePortrait(user, by_new);


but it's giving me exception as com.liferay.portal.UserPortraitTypeException which means that we get this exception when

 1   renderedImage is null as shown below.
 2    ImageBag imageBag = ImageToolUtil.read(bytes);
 3   
 4                RenderedImage renderedImage = imageBag.getRenderedImage();
 5   
 6                if (renderedImage == null) {
 7                    throw new UserPortraitTypeException();
 8                }
 9   
10       




so how can I get correct actionrequest to use liferay's way to add
image to a user ? or how can i pass correct bytes value of upload
image file to add image to user?




Or is there any other way to add user profile image in liferay ?
Juan Gonzalez
RE: Add profile image to liferay user using jsf 2.0
22. April 2013 02:30
Antwort

Juan Gonzalez

LIFERAY STAFF

Rang: Liferay Legend

Nachrichten: 2947

Eintrittsdatum: 28. Oktober 2008

Neue Beiträge

Probably you'll want to see and download jsf2 portlet demo:

https://github.com/liferay/liferay-faces/blob/3.2.x/demos/bridge/jsf2-portlet/src/main/java/com/liferay/faces/demos/bean/ApplicantBackingBean.java
Aryan sds
RE: Add profile image to liferay user using jsf 2.0
22. April 2013 03:07
Antwort

Aryan sds

Rang: Junior Member

Nachrichten: 57

Eintrittsdatum: 24. April 2012

Neue Beiträge

Juan Gonzalez:
Probably you'll want to see and download jsf2 portlet demo:

https://github.com/liferay/liferay-faces/blob/3.2.x/demos/bridge/jsf2-portlet/src/main/java/com/liferay/faces/demos/bean/ApplicantBackingBean.java



Thank you for quick reply Juan.

I have gone through ApplicantBackingBean.java file having handleFileUpload(FileUploadEvent fileUploadEvent) method, but in this method they are not using any actionrequest object or not shown way how to get correct bytes from file object to which we will pass uploading file-name.

I think that's why I am getting exception as com.liferay.portal.UserPortraitTypeException .

So how can I overcome from this exception as it occurs when renderImage is null as shown below.

1ImageBag imageBag = ImageToolUtil.read(bytes);
2
3            RenderedImage renderedImage = imageBag.getRenderedImage();
4
5            if (renderedImage == null) {
6                throw new UserPortraitTypeException();
7            }.
Juan Gonzalez
RE: Add profile image to liferay user using jsf 2.0
22. April 2013 03:51
Antwort

Juan Gonzalez

LIFERAY STAFF

Rang: Liferay Legend

Nachrichten: 2947

Eintrittsdatum: 28. Oktober 2008

Neue Beiträge

You have to read code carefully.

There you can access UploadedFile class, which has all of these methods:


https://github.com/liferay/liferay-faces/blob/3.2.x/bridge-impl/src/main/java/com/liferay/faces/bridge/model/UploadedFile.java

You can then access the file bytes.
Neil Griffin
RE: Add profile image to liferay user using jsf 2.0
22. April 2013 06:15
Antwort

Neil Griffin

LIFERAY STAFF

Rang: Liferay Legend

Nachrichten: 2378

Eintrittsdatum: 26. Juli 2005

Neue Beiträge

I would also recommend that you look at the source code for the all new primefaces3-users-portlet because it has the ability to upload a user portrait for the selected user. It has a nice feature in which it uses a JSF2 ResourceHandler to provide a URL to the image after it has been uploaded. For now you will have to build it from source, but the binary WAR will be available when Liferay Faces 3.1.2-ga3 is released.