论坛

主页 » Liferay Portal » English » 3. Development

组合视图 统一视图 树状图
讨论主题 [ 上一个 | 下一个 ]
toggle
Etian Menencia
how to catch an image?
2013年5月1日 下午8:06
答复

Etian Menencia

等级: New Member

帖子: 16

加入日期: 2013年5月1日

最近的帖子

How I can catch an image and insert it into a table?
I´m trying to get the user portrait to insert into a table and I use this code to get the object image:
long portraitId = user.getPortraitId();
Image image = ImageLocalServiceUtil.getImage(portraitId);

but when I try to insert it into to the table the output is a line like this ({imageId=11245, modifiedDate=2013-04-29 08:02:24.51, text=, type=jpg, height=79, width=79, size=1999}) and I try to use Embedded but I need an URL and I don´t know how get it from the object image.

I need some code example.
Thanks.
Murali Karteek
RE: how to catch an image?
2013年5月2日 上午2:17
答复

Murali Karteek

等级: Junior Member

帖子: 37

加入日期: 2012年3月5日

最近的帖子

Hi Etian Menencia,

I dont get your requirement .Do you want to show user portrait on page.
Or want to save the portraitId in any Db table.

Thanks& regards,
Karteek
Etian Menencia
RE: how to catch an image?
2013年5月2日 上午5:26
答复

Etian Menencia

等级: New Member

帖子: 16

加入日期: 2013年5月1日

最近的帖子

I want to show user portrait on page, especificly in a table.
Do you know how I can do it?
Thanks
Raja Seth
RE: how to catch an image?
2013年5月2日 上午5:35
答复

Raja Seth

等级: Regular Member

帖子: 164

加入日期: 2011年8月18日

最近的帖子

<img class="avatar user-info" src="<%=UserConstants.getPortraitURL(themeDisplay.getPathImage(), true, portraitId)%>" />
David H Nebinger
RE: how to catch an image?
2013年5月2日 上午5:41
答复

David H Nebinger

Community Moderator

等级: Liferay Legend

帖子: 8955

加入日期: 2006年9月1日

最近的帖子

First off, storing an image in the database is a bad idea.

Second, what you're seeing is a 'toString()' representation of the image, so clearly you've not defined the column correctly and/or have your mapping incorrect such that the object is being marshalled to a string and stored that way (hence the toString result).

The Image Gallery is the place to store images and has no marshalling issues.
Etian Menencia
RE: how to catch an image?
2013年5月2日 上午6:05
答复

Etian Menencia

等级: New Member

帖子: 16

加入日期: 2013年5月1日

最近的帖子

I don´t want storage the image into a database, what I want is show that picture in a table in the application, for example:

UserName UserPicture(Avatar) Date.
but the problem is that I don´t know how define the second column (like String, Image or object).
This is the code that I´m using.

ThemeDisplay themeDisplay = null;
long portraitId = user.getPortraitId();
Image image = ImageLocalServiceUtil.getImage(portraitId);
table.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_HIDDEN);
table.addContainerProperty("Foto", (what kind of class definition I have to put here?).class, null);
table.addContainerProperty("Nombre", String.class, null);
table.addContainerProperty("cumple", String.class, null);
table.setColumnReorderingAllowed(true);
table.setImmediate(true);
table.setWidth("100%");
table.setHeight("-1px");
table.addItem(new Object[]{UserConstants.getPortraitURL(themeDisplay.getPathImage(), true, portraitId),usuario, dia1 + "/" + mes1}, id_generator);
table.setVisible(true);

What´s I´m doing wrong?
Thanks
dave ch
RE: how to catch an image?
2013年5月2日 上午7:23
答复

dave ch

等级: Regular Member

帖子: 164

加入日期: 2012年2月6日

最近的帖子

I don´t want storage the image into a database, what I want is show that picture in a table in the application, for example:

UserName UserPicture(Avatar) Date.
but the problem is that I don´t know how define the second column (like String, Image or object).


Hi Etian ,

If above is the case then in your jsp you may simply use:

<liferay-theme:defineObjects />
<%
PortletPreferences prefs = renderRequest.getPreferences();
String print= (String)prefs.getValue(
"SomeThing", "Hello! Welcome to our Room.");
%>
<p><%= print %> <liferay-ui:user-display userId="<%= user.getUserId() %>" /></p>

Where, "liferay-ui:user-display" will display your user image.
May help you.

Thanks,
Dave
Etian Menencia
RE: how to catch an image?
2013年5月2日 上午8:03
答复

Etian Menencia

等级: New Member

帖子: 16

加入日期: 2013年5月1日

最近的帖子

I´m working with Eclipse Juno for Vaddin, and I have to develop a portlet that shows the user avatar in a table in the main page of the application, when I write the code you give me in the application shows this line {imageId=11389, modifiedDate=Mon Apr 29 08:02:28 GMT 2013, text=, type=jpg, height=79, width=79, size=1983} but not the avatar.
What can I do?
Thanks
David H Nebinger
RE: how to catch an image?
2013年5月2日 上午8:35
答复

David H Nebinger

Community Moderator

等级: Liferay Legend

帖子: 8955

加入日期: 2006年9月1日

最近的帖子

You can't leave key pieces of information like this out, or you're never going to get a response...

Vaadin has the whole StreamResource thing. You're going to want to read up on com.vaadin.terminal.server.ExternalResource and identify the full URL you need to pass in so Vaadin will be able to get the image from the portal.
Etian Menencia
RE: how to catch an image?
2013年5月2日 上午8:42
答复

Etian Menencia

等级: New Member

帖子: 16

加入日期: 2013年5月1日

最近的帖子

Thanks, I´m new here and I need learn how ask.
Do you have some documentation about this because I start with liferay one week ago and are some kind og things I don´t know yet.
Thanks
Etian Menencia
RE: how to catch an image?
2013年5月16日 上午6:56
答复

Etian Menencia

等级: New Member

帖子: 16

加入日期: 2013年5月1日

最近的帖子

I finally find the way I can get the user image and show in a table, was very simple, with this 3 code lines we can resolve the problem

ThemeDisplay themeDisplay = new ThemeDisplay();
String url = user.getPortraitURL(themeDisplay);
Label prueba = new Label("<img src=\"http://localhost:8080/image/logo" + dirfoto + "\"/>",Label.CONTENT_XHTML);
Thanks to everyone who advice me.