【问题标题】:Primefaces: graphicImage not displaying when invoking page from URL (non <h:commandLink)Primefaces:从 URL 调用页面时不显示图形图像(非 <h:commandLink)
【发布时间】:2011-05-14 16:12:31
【问题描述】:

在某些情况下,我在尝试在 facelet 页面(从数据库中检索)上显示图像并且页面由 URL(不是h:命令链接)。它适用于通过 h:commandButton 处理请求的其他页面。然而,除了图像之外的所有数据都出现在以下场景中......

  1. fundraiseView.xml(facelet 页面) html ... p:graphicImage value="#{fundraisePage.picture}"/ ... /html

  2. FundraisePage(带有请求参数的请求范围支持 bean)

    @ManagedBean
    @RequestScoped
    public class FundraisePage extends BackingBean {
    
    
      @EJB DataSBLocal dataSB;
      StreamedContent picture;
    
    
      @ManagedProperty(value="#{param.id}")
      private int id;
    
    
      @PostConstruct
      public void init() {
        this.fundRaiseEO = dataSB.getFundRaiseIndividual(id);
        InputStream inputStream = new ByteArrayInputStream(this.fundRaiseEO.getPicture());
        this.setPicture(new DefaultStreamedContent(inputStream, "image/jpeg"));
      }
    
  3. 当我通过 http://...../faces/fundraiseView.xml?id=1 调用页面时,页面返回显示 id 1 的所有数据,但不显示图片。我确定这与我调用页面的方式有关(因为我让它在其他地方工作)但是我需要它是在 JSF 包装标签之外发起的请求。

非常感谢任何见解或建议。

谢谢, 乔纳森

【问题讨论】:

    标签: jsf-2 primefaces


    【解决方案1】:

    在另一个帖子中找到了答案。

    Loading a set of images with primefaces

    我需要在 p:graphicImage 标记中使用标记 f:parm name="id" value="#{fundraisePage.id}" 以便它接受 id 作为查找参数。以及将图像标签上的值更改为属性中的此方法...

    公共 StreamedContent getImage () {

         FundRaise fundRaiseEO = new FundRaise();
         fundRaiseEO = dataSB.getFundRaiseIndividual(id);
         return new DefaultStreamedContent(new ByteArrayInputStream(fundRaiseEO.getPicture()), "image/jpeg"); \\ or whatever your image mime type.
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-30
      • 1970-01-01
      • 2022-06-11
      • 2012-07-23
      • 1970-01-01
      • 1970-01-01
      • 2021-09-07
      相关资源
      最近更新 更多