フォーラム

ホーム » Liferay Faces » Liferay Faces - English

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
Aryan sds
Add profile image to liferay user using jsf 2.0
2013/04/22 3:24
答え

Aryan sds

ランク: Junior Member

投稿: 57

参加年月日: 2012/04/24

最近の投稿

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
2013/04/22 2:30
答え

Juan Gonzalez

LIFERAY STAFF

ランク: Liferay Legend

投稿: 1847

参加年月日: 2008/10/28

最近の投稿

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
2013/04/22 3:07
答え

Aryan sds

ランク: Junior Member

投稿: 57

参加年月日: 2012/04/24

最近の投稿

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
2013/04/22 3:51
答え

Juan Gonzalez

LIFERAY STAFF

ランク: Liferay Legend

投稿: 1847

参加年月日: 2008/10/28

最近の投稿

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
2013/04/22 6:15
答え

Neil Griffin

LIFERAY STAFF

ランク: Liferay Legend

投稿: 1981

参加年月日: 2005/07/26

最近の投稿

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.