Where should I handle image urls in JSF?

For the uni assignment, I am making a JSF webapp for a poker game. Images in the player's hand are displayed as images. What would be the "cleanest" way to map the map / map rank to the URL of the linked image?

I am currently leaning towards either using any returned map # toString or handling it in a bean fallback, simply because neither the model nor the controller is the right place to do this.

(This question is somewhat subjective, but again, so is every design question. I'm looking for some obvious solution that I missed, not a discussion.)

+1


a source to share


1 answer


If you are against creating the url in the bean backup, you can use the EL function to translate:

<h:graphicImage value="#{fnlib:getImageUrlFor(myBean.cardInstance)}" />

      



This way your backing beans can return an instance of the map class directly (I assume it is an enum) and the function will map it to the image url. You can find an example of how to implement the function in this answer . You might have to look at FacesContext.getCurrentInstance (). GetExternalContext () if you want to create a url that will be valid no matter what directory your JSP is in in relation to images (I can't remember which h: graphicImage rules the top of my head uses).

+1


a source







All Articles