0

i'm trying to find a solution to load image names from a database and display them on a webpage. Basically, when i display an image i do it like this:

<h:graphicImage value="#{resource['mywebapp:image.png']}">
</h:graphicImage>

So now instead of image.png i would like to dynamically load alternative images. Problem is, that i can't use an EL nested expression inside another one (at least i have not found out how). To put the logic into the backing bean also does not help in this case, because then it is rendered like that:

 <img src="#{resource['mywebapp:somedynamicallyloadedimagename.png']}">
</img>

The only thing that works, is to directly generate the path in the backing bean:

public String getImage() {
    this.image = "/mywebapp/javax.faces.resource/"+this.image+".jsf?ln=images";
            return image;
}                                       

However this "solution" is far from elegant, since everything is hardcoded and this is nothing i'm going to put in a production app. What would be a good solution to do this? I would like to avoid putting the images into the database and using primefaces.. Since i'm not an experienced JSF coder (as you can probably tell), i would highly appreciate some thoughts on this topic...thanks in advance!

1 Answer 1

1

Try

<h:graphicImage library="images" name="#{generated.name}" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.