0

I'm unable to display image of external host on JSF page. In my case it is Apache file server. I'm creating image URL in @RequestScoped bean and then trying to pass it as String in @ViewScoped bean to frontend.

I've tried to display image in two ways: First by loading it with JSF:

<h:graphicImage name="#{myViewScopedBean.myObject.mainImageUrl}" />

And then with html <img> tag as referenced in this answer.

Afterwards I've tried to print all attributes of myObject. All String attributes are displayed well, except mainImageUrl. and I'm 100% sure that I'm setting mainImageUrl on backend.

What can provoke this problem? Is there any security JSF configuration?

Community
  • 1
  • 1
andriy
  • 4,074
  • 9
  • 44
  • 71
  • 1
    You forgot to tell the generated HTML output. That's all what the browser gets. The browser is the one responsible for downloading and displaying the image. Edit your question to include the JSF-generated `` element as the browser has retrieved (do rightclick, *View Source* in browser to see it). – BalusC Jan 23 '15 at 12:59
  • I'm simply getting ``. I'm sure that i'm setting image url to `myViewScopedBean.myObject.mainImageUrl`, but looks like it doesn't getting to frontend – andriy Jan 23 '15 at 13:02
  • That will indeed happen when you try to reference it as an internal JSF resource while it's not an internal JSF resource at all. I'm more interested in `` approach. – BalusC Jan 23 '15 at 13:06
  • ok, I managed to display it in `` tag. Thank you – andriy Jan 23 '15 at 14:34

1 Answers1

1

The name attribute of <h:graphicImage> should represent a JSF resource name, not an URL. JSF resources are explained in among others How to reference CSS / JS / image resource in Facelets template? If you intend to specify a real URL, then you should be using value attribtue instead, or just plain HTML <img>.

So, either

<h:graphicImage value="#{myViewScopedBean.myObject.mainImageUrl}" />

Or

<img src="#{myViewScopedBean.myObject.mainImageUrl}" />

If that still doesn't work, then apparently the URL is plain wrong. Verify the generated HTML output and the browser's builtin HTTP traffic monitor (press F12). You should be able to open the image independently by copypasting exactly that URL straight into browser's address bar.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555