Primefaces dynamic image in Datatable

478 views Asked by At

I already found some resource :

But my development environment is a little different.

  • JSF 2.0
  • Primefaces 4.0
  • Spring 3.1.1
  • Jboss Seam 2.3
  • JBoss AS 7.1.1 Final

If I don't use JBoss Seam, it is ok. I cannot remove JBoss Seam because of there are a lot of classes in my project. Our team will have to continue develop with these environment.

example_2.xhtml

<h:form id="attachmentForm" enctype="multipart/form-data">
    <p:dataTable var="attachment" value="#{ImageActionBean.proposalAttachmentList}" rows="1" paginator="true">
        <p:column style="width:50px;">
            <h:outputText value="#{attachment.id}" />
        </p:column>
        <p:column style="width:150px;">
            <h:outputText value="#{attachment.contextType}" />
        </p:column>
        <p:column>
            <p:graphicImage value="#{ImageActionBean.streamedImage}">
                <f:param name="attachmentId" value="#{attachment.id}"/>
            </p:graphicImage>
        </p:column>
    </p:dataTable>
</h:form>

ImageActionBean.java

@Scope(ScopeType.CONVERSATION)
@Name("ImageActionBean")
public class ImageActionBean {
    private boolean initFlag = true;
    @In("#{ProposalItemService}")
    private IProposalItemService proposalItemService;
    @In("#{AttachmentFilter}")
    private AttachmentFilter attachmentFilter;
    private List<ProposalAttachment> proposalAttachmentList;

    @Begin(join = true)
    public void init() {
        initFlag = false;
        proposalAttachmentList = proposalItemService.findProposalAttachById("PIT00000000000010116012014");
    }   

    public boolean getInitFlag() {
        return initFlag;
    }

    public List<ProposalAttachment> getProposalAttachmentList() {
        return proposalAttachmentList;
    }

    public StreamedContent getStreamedImage() {
        FacesContext context = FacesContext.getCurrentInstance();
        if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
            return new DefaultStreamedContent();
        } else {
            String attachmentId = context.getExternalContext().getRequestParameterMap().get("attachmentId");
            System.out.println("Attachment ID : " + attachmentId);
            IAttachment attachment = attachmentFilter.findAttachment("ProposalAttachment", attachmentId);
            return new DefaultStreamedContent(new ByteArrayInputStream(attachment.getData()), attachment.getContextType());
        }       
    }
}

DateTable :

enter image description here

Stack Trace :

17:16:18,257 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) 17:16:18,257 DEBUG [org.jboss.seam.contexts.Contexts] destroying: org.jboss.seam.core.manager

17:16:18,257 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) 17:16:18,257 DEBUG [org.jboss.seam.contexts.Contexts] destroying: attachment

17:16:18,257 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) 17:16:18,257 DEBUG [org.jboss.seam.contexts.Contexts] destroying: org.jboss.seam.transaction.synchronizations

17:16:18,257 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) 17:16:18,257 DEBUG [org.jboss.seam.contexts.Contexts] destroying: org.jboss.seam.web.servletContexts

17:16:18,257 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) 17:16:18,257 DEBUG [org.jboss.seam.contexts.Contexts] destroying: org.jboss.seam.web.requestContextPath

17:16:18,257 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) 17:16:18,257 DEBUG [org.jboss.seam.contexts.Contexts] destroying: org.jboss.seam.core.events

17:16:18,257 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) 17:16:18,257 DEBUG [org.jboss.seam.contexts.Contexts] destroying: org.jboss.seam.web.requestServletPath

17:16:18,257 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) 17:16:18,257 DEBUG [org.jboss.seam.contexts.FacesLifecycle] <<< End JSF request for /insudemo/view/example_2.se
am

17:16:18,277 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) 17:16:18,277 DEBUG [org.jboss.seam.init.Initialization] Using Java hot deploy

17:16:18,280 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) 17:16:18,280 DEBUG [org.jboss.seam.util.Resources] Loaded resource from servlet context: jndi:/default-host/ins
udemo/view/login.page.xml

17:16:18,280 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) 17:16:18,280 DEBUG [org.jboss.seam.util.Resources] Loaded resource from servlet context: jndi:/default-host/ins
udemo/WEB-INF/pages.xml

17:16:18,280 SEVERE [org.primefaces.application.PrimeResourceHandler] (http-localhost-127.0.0.1-8080-1) Error in streaming dynamic resource. null
17:16:18,365 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) 17:16:18,365 DEBUG [org.jboss.seam.init.Initialization] Using Java hot deploy

17:16:18,368 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) 17:16:18,368 DEBUG [org.jboss.seam.util.Resources] Loaded resource from servlet context: jndi:/default-host/ins
udemo/view/login.page.xml

17:16:18,369 INFO  [stdout] (http-localhost-127.0.0.1-8080-1) 17:16:18,369 DEBUG [org.jboss.seam.util.Resources] Loaded resource from servlet context: jndi:/default-host/ins
udemo/WEB-INF/pages.xml

17:16:18,369 SEVERE [org.primefaces.application.PrimeResourceHandler] (http-localhost-127.0.0.1-8080-1) Error in streaming dynamic resource. Expression cannot be null

BTW, I did not see my printed message(System.out.println("Attachment ID : " + attachmentId);) in stack trace

0

There are 0 answers