簡體   English   中英

如何使用p:graphicImage在p:dataGrid中顯示圖像

[英]How to show images in p:dataGrid using p:graphicImage

我有ap:dataGrid,顯示公司。 這些公司有徽標,我想展示他們的徽標
在dataGrid下的名稱,但圖像不會出現在頁面中。 只顯示破損的圖像方塊。

xhtml代碼;

 <p:dataGrid value="#{BDS_Company.companyList}" var="cmp" rows="5" columns="3">
       <p:column>
          <h:panelGrid columns="1">
             <h:outputLabel value="#{cmp.cmpName}"/>
             <h:outputLabel value="#{cmp.cmpEmail}"/>
             <p:graphicImage value="#{BDS_Company.companyLogo(cmp)}"/>
           </h:panelGrid>
       </p:column>
 </p:dataGrid>

托管bean代碼;

public DefaultStreamedContent companyLogo(BdsCompany company) {
        if (company != null) {
            if (company.getCmpLogo() != null) {
                InputStream is = new ByteArrayInputStream(company.getCmpLogo().getDocFile());
                return new DefaultStreamedContent(is);
            }
        }
        return null;
    }

當我更改這樣的代碼時,我采取了異常“Method companyLogo not found”

public DefaultStreamedContent getCompanyLogo(BdsCompany company) {
        if (company != null) {
            if (company.getCmpLogo() != null) {
                InputStream is = new     ByteArrayInputStream(company.getCmpLogo().getDocFile());
                return new DefaultStreamedContent(is);
            }
        }
        return null;
 }

但是另一個我用getPersonPicture()的頁面顯示了loged人的個人資料圖片並且沒有參數效果很好! 我不明白為什么公司的徽標沒有出現在頁面中:/

任何人都可以幫助我解決這種情況或建議另一種方式來顯示圖像?

提前致謝 。

為graphicImage值創建一個DefaultStreamedContent的String url(/images/company.png)。 編寫一個servlet,添加到web.xml並映射您的圖像URL(/ images / *)。

在servlet doGet中對數據庫執行任何操作,並將您的圖像流作為響應返回。

http://rajivas.wordpress.com/tag/writing-directly-to-response-stream-in-jsf/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM