problem with p:graphicImage and stream

UI Components for JSF
Post Reply
User avatar
DiogoBernard
Posts: 29
Joined: 27 Sep 2010, 23:23

14 Oct 2010, 16:44

why my code does not work ?

Code: Select all

<p:galleria effect="#{imagemBean.effect}" effectSpeed="1000">
		     <ui:repeat value="#{imagemBean.pecas}" var="peca">
		         <p:graphicImage value="#{imagemBean.image}" />
		     </ui:repeat>  
  		 </p:galleria>

Code: Select all

public StreamedContent getImage() throws FileNotFoundException {
		HttpServletRequest requestScope = (HttpServletRequest) FacesContext.
				getCurrentInstance().getExternalContext().getRequest();		
		Pecas peca = (Pecas)requestScope.getAttribute("peca");

		if(peca != null){
			File file = new File(peca.getFile()); //get String "/opt/image/etc.jpg" for exemplo
			System.out.println(file.exists());
			FileInputStream stream = new FileInputStream(file);
	        image = new DefaultStreamedContent(stream, "image/jpeg");
		}
        return image;
    }
but I tried a test and it worked ! I need to know the reason why worked

Code: Select all

<p:galleria effect="#{imagemBean.effect}" effectSpeed="1000">
		     <ui:repeat value="#{imagemBean.pecas}" var="peca">
		         <p:graphicImage value="#{imagemBean.image}" />
		     </ui:repeat>  
  		 </p:galleria>

Code: Select all

public StreamedContent getImage() throws FileNotFoundException {
		if(peca != null){
			File file = new File("/opt/image/etc.jpg"); 
			System.out.println(file.exists());
			FileInputStream stream = new FileInputStream(file);
	        image = new DefaultStreamedContent(stream, "image/jpeg");
		}
        return image;
    }

healeyb
Posts: 365
Joined: 07 Apr 2010, 16:05

15 Oct 2010, 00:12

So, does it work or not work? if it works why the question?

You need to much clearer if you need someone to help you. My apologies
if this is simply a language issue.

Regards,
Brendan.

User avatar
DiogoBernard
Posts: 29
Joined: 27 Sep 2010, 23:23

15 Oct 2010, 16:06

it doesnt work with this code !

Code: Select all

public StreamedContent getImage() throws FileNotFoundException {
      HttpServletRequest requestScope = (HttpServletRequest) FacesContext.
            getCurrentInstance().getExternalContext().getRequest();      
      Pecas peca = (Pecas)requestScope.getAttribute("peca");

      if(peca != null){
         File file = new File(peca.getFile()); //get String "/opt/image/etc.jpg" for exemplo
         System.out.println(file.exists());
         FileInputStream stream = new FileInputStream(file);
           image = new DefaultStreamedContent(stream, "image/jpeg");
      }
        return image;
    }
but, it this code worked !

Code: Select all

public StreamedContent getImage() throws FileNotFoundException {
      if(peca != null){
         File file = new File("/opt/image/etc.jpg");
         System.out.println(file.exists());
         FileInputStream stream = new FileInputStream(file);
           image = new DefaultStreamedContent(stream, "image/jpeg");
      }
        return image;
    }
I wonder what's wrong ? and what's problem the first code ?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 55 guests