p:graphicImage in version 10.0.2

UI Components for JSF
Post Reply
iexpertise
Posts: 26
Joined: 28 Oct 2014, 15:21

17 Jun 2021, 21:31

I'm migrating from version 6.1 to version 10. I've fixed most of the issues. So I'm trying to improve some things. I'm replacing the h:graphicImage component with the p:graphicImage to fetch the content programmatically. It is giving the following message "Failed to load resource: the server responded with a status of 500 (Internal Server Error)" something related to the dynamiccontent.properties.xhtml file.

This should be a common mistake that many like me make when using the component this way.

Any idea why?

no success searching in previous posts viewtopic.php?f=3&t=65121&p=188927&hili ... ge#p188927

Code: Select all

<p:graphicImage value="#{selecaoClienteMB.carregarBrasao(cliente)}" />

Code: Select all

public StreamedContent carregarBrasao(ClienteVO clienteAux) {
	
		try {
			
			if (clienteAux.getBrasao().getUniarq() != null && clienteAux.getBrasao().getCaminh() != null && clienteAux.getBrasao().getHasarq() != null && clienteAux.getBrasao().getExtarq() != null) {
				
				String caminhoArquivoFisicoOrigem = clienteAux.getBrasao().getUniarq().getCamuni() + "/" + clienteAux.getBrasao().getCaminh();
				caminhoArquivoFisicoOrigem += "/" + clienteAux.getBrasao().getHasarq() + clienteAux.getBrasao().getExtarq();

				File arquivo = new File(caminhoArquivoFisicoOrigem);
				
	            return DefaultStreamedContent.builder()
	                    .contentType("image/png")
	                    .stream(() -> {
	                        try {
	                        	return new FileInputStream(arquivo);
	                        }
	                        catch (Exception e) {
	                            e.printStackTrace();
	                            return null;
	                        }
	                    })
	                    .build();
			}
			
			return null;
			
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
	}

NOTiFY
Posts: 270
Joined: 25 May 2016, 22:57
Location: Cambridge, UK

18 Jun 2021, 10:47

Using PF 10.0.2 with 'p:graphicImage' with 'o:graphicImag' (https://showcase.omnifaces.org/components/graphicImage) only worked for me. On WildFly etc., see my 'signature';

Code: Select all

<p:galleria value="#{imagesController.images}" var="image" panelWidth="1500" panelHeight="1000" showCaption="true">
    <o:graphicImage value="#{nOTiFYMotorcycleController.imageFileUrlPng}" dataURI="true"/>
</p:galleria>

Code: Select all

/**
  * @return List
*/
public List<String> getImages() {
    LOGGER.info(">>>>> ImagesController List images = {}", images);
    
    return images;
}

Code: Select all

<!--  Galleria  - o:graphicImage -->
<o:graphicImage value="#{nOTiFYMotorcycleController.imageFileUrlPng}" dataURI="true"/>

Code: Select all

 public InputStream getImageFileUrlPng() throws FileNotFoundException {
 
        StringBuffer stringBuffer = new StringBuffer();
        if (selectedMotorcycleList.size() == ONE) {
            stringBuffer.append(selectedMotorcycleList.get(ZERO).getImage().getFile());
            stringBuffer.append(selectedMotorcycleList.get(ZERO).getImage().getUrl());
            stringBuffer.append(selectedMotorcycleList.get(ZERO).getModel());
            stringBuffer.append(FORWARD_SLASH);
            stringBuffer.append(selectedMotorcycleList.get(ZERO).getImage().getPng());
        } else {
            stringBuffer.append(motorcycleList.get(ZERO).getImage().getFile());
            stringBuffer.append(motorcycleList.get(ZERO).getImage().getUrl());
            stringBuffer.append(motorcycleList.get(ZERO).getImage().getPng());
        }
        return new FileInputStream(new File(stringBuffer.toString()));
    }
Last edited by NOTiFY on 20 Jun 2021, 16:08, edited 2 times in total.
PrimeFace (Elite) 10.0.4
Mojarra JSF 2.3.14.SP04 & OmniFaces 3.11.1

WildFly 24.0.1.Final Weld 4.0.1 (Final) & CDI 3.0
Java OpenJDK 16.0.1, Kotlin 1.5.21, Gradle (Kotlin) 7.1.1, MongoDB 5.0.1
IntelliJ IDEA 2021.1.3, macOS Big Sur 11.5.1

tandraschko
PrimeFaces Core Developer
Posts: 3850
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

18 Jun 2021, 11:59

Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 24 guests