开发者

get path of image from bean object to jsf page

开发者 https://www.devze.com 2023-04-12 19:31 出处:网络
i have an object that holds an imageIcon, in a jsf page this line suppose to show the开发者_StackOverflow img

i have an object that holds an imageIcon, in a jsf page this line suppose to show the开发者_StackOverflow img

    <h:graphicImage value="#{myObj.img }"></h:graphicImage>

now in myObj the getImg method return the path of the img as a string, also when entered view source in chrome i see the full path of the img but no img is shown.

any suggestions?


Apparently you've just returned an invalid URL to it, or you misunderstood how the image URL is been resolved relative to the URL of the current page.

First, you need to figure the absolute URL of the image. It should be the URL as you see in browser address bar when you would like to obtain the image, for example:

http://localhost:8080/contextname/images/foo.png

If this returns a valid image, then you should make sure that the <h:graphicImage> value ultimately ends up with the same path:

<img src="/contextname/images/foo.png" />

You can achieve this with:

<h:graphicImage value="#{myObj.img}" />

where #{myObj.img} must return the string "images/foo.png".

0

精彩评论

暂无评论...
验证码 换一张
取 消