jsf 2 - graphicImage and streamed content primefaces and jsf -


so, have managed upload images desired location , gave name these images same name of object property example: fruit contains name apple , have apple.jpg. able see image directly when call <p:graphicimage name="apple.jpg" id="image" width="40" height="20" library="images" />

imagine have datatable contains fruits , when click on fruit want picture of fruit.

if(item.getfruit().getlogo().getname() == item.getfruit().getname()){    //show me image } 

i've searched whole stack , i've got lost.

i assume that:

  • you have folder images
  • each image url saved string field fruit entity.

so, when load fruit entity database, have image full url.

<ui:repeat var="fruit" value="#{fruitbean.fruitlistfromdatabase}">     <h:graphicimage value="#{fruit.imageurl}" rendered="#{!empty fruit.imageurl}" />         <h:graphicimage library="images" name="no-image.png" rendered="#{empty fruit.imageurl}" />   </ui:repeat> 

the previous code render image per fruit, in case of no image uploaded (imageurl null), custom no-image.png show.

h:graphicimage must use specifying library , name attributes when have image inside resources folder of webapp.

use h:graphicimage value attribute, show full image url.

why must not store uploaded images inside application resources file? because on redeploy, images lost.

to serve custom folder, can use aproach allows create virtual served directory, example, if using glassfish, in glassfish-web.xml, need make reference external folder images:

<property name="alternatedocroot_1" value="from=/media/* dir=/data" /> 

now, images can found: "your-domain.com/media/some-image.png"


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -