0

I have a simple form with a fileupload. the file upload and backing bean works perfect but i want to display uploaded images after upload. I've used ui:repeat but only the first image repeats for all uploads! I used multiple p:graphicImage instead of ui:repeat and result is absolutely correct. but i have to use ui:repeat or p:galleria.

here is ui:repeat usage with wrong result

<ui:repeat value="#{applicationImagesBean.screenidx}" var="idx">
    <p:graphicImage value="#{applicationImagesBean.getScreen(idx)}" height="320"/>
</ui:repeat>

and here is multiple p:graphicImage which is correct but it's not what i want

<p:graphicImage value="#{applicationImagesBean.getScreen(0)}" height="320"/>
<p:graphicImage value="#{applicationImagesBean.getScreen(1)}" height="320"/>
<p:graphicImage value="#{applicationImagesBean.getScreen(2)}" height="320"/>

note that screenidx is a simple list contains 0,1,2,3, ... as integers

public StreamedContent getScreen(Integer idx) {
    try {
        File file = screenFiles.get(idx);
        return new DefaultStreamedContent(new FileInputStream(file), null, "" + idx.intValue());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

in both samples I had a breakpoint on getSceen and idx has been sent correctly to getScreen but the result was different.

I tired a cache = false and a timestamp parameter but no result.

Meysam Te.
  • 46
  • 6
  • 1
    possible duplicate of [Display image from database with p:graphicImage](http://stackoverflow.com/questions/8207325/display-image-from-database-with-pgraphicimage) and [How to use `` with DefaultStreamedContent in an ui:repeat?](http://stackoverflow.com/questions/10944673/how-to-use-pgraphicimage-with-defaultstreamedcontent-in-an-uirepeat/10951201#10951201). In a nutshell: use `` instead. – BalusC Jun 04 '13 at 12:04
  • i tried f:param too, the result is same and my problem still there – Meysam Te. Jun 04 '13 at 12:56
  • Did you also read the linked answers from top to bottom and **understand** the concrete problem? Your bean and method also needs to be changed and such. – BalusC Jun 04 '13 at 12:56
  • Thank you. I found the problem. when we use el2 and pass idx as a method parameter, jsf use that in render time (PhaseId.RENDER_RESPONSE). and in second call of the method, parameter is always idx = 0 (i dont know why!). – Meysam Te. Jun 04 '13 at 13:34
  • That part was already explained in the linked answers. Why exactly didn't you bother to *read* them? – BalusC Jun 04 '13 at 13:37

0 Answers0