Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Etian Menencia
how to catch an image?
May 1, 2013 8:06 PM
Answer

Etian Menencia

Rank: New Member

Posts: 16

Join Date: May 1, 2013

Recent Posts

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?
May 2, 2013 2:17 AM
Answer

Murali Karteek

Rank: Junior Member

Posts: 37

Join Date: March 5, 2012

Recent Posts

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?
May 2, 2013 5:26 AM
Answer

Etian Menencia

Rank: New Member

Posts: 16

Join Date: May 1, 2013

Recent Posts

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?
May 2, 2013 5:35 AM
Answer

Raja Seth

Rank: Regular Member

Posts: 217

Join Date: August 18, 2011

Recent Posts

<img class="avatar user-info" src="<%=UserConstants.getPortraitURL(themeDisplay.getPathImage(), true, portraitId)%>" />
David H Nebinger
RE: how to catch an image?
May 2, 2013 5:41 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11295

Join Date: September 1, 2006

Recent Posts

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?
May 2, 2013 6:05 AM
Answer

Etian Menencia

Rank: New Member

Posts: 16

Join Date: May 1, 2013

Recent Posts

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?
May 2, 2013 7:23 AM
Answer

dave ch

Rank: Regular Member

Posts: 164

Join Date: February 6, 2012

Recent Posts

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?
May 2, 2013 8:03 AM
Answer

Etian Menencia

Rank: New Member

Posts: 16

Join Date: May 1, 2013

Recent Posts

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?
May 2, 2013 8:35 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11295

Join Date: September 1, 2006

Recent Posts

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?
May 2, 2013 8:42 AM
Answer

Etian Menencia

Rank: New Member

Posts: 16

Join Date: May 1, 2013

Recent Posts

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?
May 16, 2013 6:56 AM
Answer

Etian Menencia

Rank: New Member

Posts: 16

Join Date: May 1, 2013

Recent Posts

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.