Reputation: 327
i use primefaces on jsf framework, i have in my database a field that save the url source of where the image was saved for example:
Table Person:
id: integer
name: varchar
img: varchar ("C:\images\person\person1.jpg")
so, in my method in java y return that url string but when i put to the graphic image label
it load like this http://localhost:8080/..../C:\images\person\person1.jpg
any ideas???
<p:graphicImage value="#{person.img}"/>
this line is in pure html
<img src="C:\images\person\person1.jpg" alt=""/>
Upvotes: 0
Views: 429
Reputation: 3443
It seems that you're expecting that image to be served by the default servlet or as a JSF resource since it's on your filesystem. This won't happen unless that imagine is part of your web-app.
In order to serve it, return a StreamedContent
object from your method, something like this return new StreamedContent(new FileInputStream(getPathFromDatabase()));
. Note that the returned property should be available in session scope or request scope, because the image is served by the Primefaces resource handler in a separate request. This means that if you return the StreamedContent object from a view scoped bean, it won't be available on subsequent requests.
Upvotes: 1
Reputation: 191
The value attribute of graphicImage is a relative url (or a binary stream if you implement StreamedContent), relative to your context.
That means it is appended to the url of your application, resulting in something like: http://hostname:port/appname/relative_image_url
.
Upvotes: 0