掲示板
Add profile image to liferay user using jsf 2.0
11年前 に Aryan sds によって更新されました。
Add profile image to liferay user using jsf 2.0
Junior Member 投稿: 57 参加年月日: 12/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
where user is userid and bytes_file is array of bytes
to get value of bytes_file liferay use this way.
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.
or
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 ....
but it's giving me exception as com.liferay.portal.UserPortraitTypeException which means that we get this exception when
Or is there any other way to add user profile image in liferay ?
Now as we know to add profile image to user we use
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.
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
File file=uploadRequest.getFile(fileName);
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.
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
ActionRequest actionRequest = (ActionRequest) externalContext.getRequest();
or
LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
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 ....
step 1. byte[] bytes_file = event.getFile().getFileName().getBytes();
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
renderedImage is null as shown below.
ImageBag imageBag = ImageToolUtil.read(bytes);
RenderedImage renderedImage = imageBag.getRenderedImage();
if (renderedImage == null) {
throw new UserPortraitTypeException();
}
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 ?
11年前 に Juan Gonzalez によって更新されました。
RE: Add profile image to liferay user using jsf 2.0
Liferay Legend 投稿: 3089 参加年月日: 08/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
https://github.com/liferay/liferay-faces/blob/3.2.x/demos/bridge/jsf2-portlet/src/main/java/com/liferay/faces/demos/bean/ApplicantBackingBean.java
11年前 に Aryan sds によって更新されました。
RE: Add profile image to liferay user using jsf 2.0
Junior Member 投稿: 57 参加年月日: 12/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.
ImageBag imageBag = ImageToolUtil.read(bytes);
RenderedImage renderedImage = imageBag.getRenderedImage();
if (renderedImage == null) {
throw new UserPortraitTypeException();
}.
11年前 に Juan Gonzalez によって更新されました。
RE: Add profile image to liferay user using jsf 2.0
Liferay Legend 投稿: 3089 参加年月日: 08/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.
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.
11年前 に Neil Griffin によって更新されました。
RE: Add profile image to liferay user using jsf 2.0
Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
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.