2012-07-25 2 views

답변

2

OmniFaces는 아직 —에 대한 유틸리티를 제공하지 않습니다.

이미지 파일이 디스크 파일 시스템에있는 경우 일반 URL로 액세스 할 수 있도록 servletcontainer 구성에 가상 컨텍스트를 만들어야합니다. Load images from outside of webapps/webcontext/deploy folder using <h:graphicImage> or <img> tag을 참조하십시오.

이미지 파일이 DB에 저장된 경우 DB의 이미지 중 InputStream을 HTTP 응답의 OutputStream에 쓰는 간단한 서블릿을 만들어야합니다. How to retrieve and display images from a database in a JSP page?도 참조하십시오 (JSP/HTML을 필요로하지 않음에 유의하십시오. <h:graphicImage>은 단순히 HTML <img> 요소를 생성하기 때문에 유용 할 수 있습니다).

PrimeFaces <p:graphicImage>이 있지만 구현하기에 조금 비현실적입니다. Display dynamic image from database with p:graphicImage and StreamedContent을 참조하십시오.


업데이트는 :

<o:graphicImage value="#{imageStreamer.getById(bean.imageId)}" /> 
: OmniFaces 2.0 이후 (JSF 2.2) 바로 아래처럼 직관적 인 방법에 @ApplicationScoped 관리 빈에서 byte[] 또는 InputStream 속성을 참조하는 다른 사람의 사이에서 지원하는 <o:graphicImage> 성분있다 PrimeFaces <p:graphicImage>에 반하는에서
@Named 
@ApplicationScoped 
public class ImageStreamer { 

    @Inject 
    private ImageService service; 

    public InputStream getById(Long id) { // byte[] is also supported. 
     return service.getContent(id); 
    } 

} 

, 아니 <f:param>이 필요하고 EL 메소드 인수는 렌더링 응답 단계에서 평가되지만 EL 메소드 자체는 브라우저가 실제로 이미지를 요청할 때만 호출됩니다. the showcasethe blog on the subject을 참조하십시오.

관련 문제