Search code examples
jsfgraphicimage

JSF - graphicImage - replace broken image


I am wondering, is there a way to replace broken image with some other one in JSF when using grapicImage?

I found a solution in JavaScript:

<img src="image.png" onError="this.onerror=null;this.src='/images/noimage.gif';" />

However graphicImage doesn't support onError handling.


Solution

  • It possible using a simple jQuery script:

    <script type="text/javascript">
          jQuery(document).ready(function() {
          var $ = jQuery;
          var Element = ".poster";
          $(Element).error(function () {
              $(this).unbind("error").attr("src", "error.jpeg");
          });
          });
    </script>