Anzeigen von DB-Bildern mit ContentFlow (Coverflow) IllegalStateException-Fehler

Ich verwende derzeit einen Bild-Coverflow eines Drittanbieters (http://www.jacksasylum.eu/ContentFlow/), um Bilder anzuzeigen, die in einer Datenbank gespeichert werden. Ich benutze Java, JPA und RichFaces dafür. Ich habe ein Image-Servlet für die Image-Anzeige eingerichtet. Ich habe eine Richfaces-Datenbank eingerichtet und möchte nur Bilder ausgewählter Datensätze im Coverflow anzeigen. Diese Funktionalität ist vorhanden, um dies zu tun. Ich habe eine Befehlsschaltfläche zum Rendern des Bild-Coverflow in einem OutputPanel. Meine Bilder werden ohne Fehler korrekt auf der Seite angezeigt, bevor der Coverflow implementiert wird. Ich weiß also, dass meine zugrunde liegende Funktionalität wie gewünscht funktioniert. Das Problem ist, dass wenn ich den Coverflow implementiere, indem ich bestimmte div-Tags wie angewiesen um meine img-Tags lege, die folgende Fehlermeldung angezeigt wird:

Error Rendering View[/index.xhtml]: java.lang.IllegalStateException: Cannot create a session after the response has been committed
at org.apache.catalina.connector.Request.doGetSession(Request.java:2636) [jbossweb-7.0.10.Final.jar:]
at org.apache.catalina.connector.Request.getSession(Request.java:2375) [jbossweb-7.0.10.Final.jar:]
at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:841) [jbossweb-7.0.10.Final.jar:]
at com.sun.faces.context.ExternalContextImpl.getSession(ExternalContextImpl.java:155) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
at javax.faces.context.ExternalContextWrapper.getSession(ExternalContextWrapper.java:396) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final]
at com.sun.faces.renderkit.ServerSideStateHelper.writeState(ServerSideStateHelper.java:175) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
at com.sun.faces.renderkit.ResponseStateManagerImpl.writeState(ResponseStateManagerImpl.java:122) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
at com.sun.faces.application.StateManagerImpl.writeState(StateManagerImpl.java:166) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
at com.sun.faces.application.view.WriteBehindStateWriter.flushToWriter(WriteBehindStateWriter.java:225) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:419) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final]
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.10.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.10.Final.jar:]
at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.10.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.10.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.10.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.10.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.0.Final.jar:7.1.0.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:154) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.10.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.10.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.10.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.10.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.10.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.10.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.10.Final.jar:]
at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_32]

Hier ist ein Teil meines Codes:

ImgServlet.java

 /**
   * Servlet implementation class ImgServlet
   */
    @WebServlet(name = "ImgServlet", urlPatterns = {"/ImgServlet/*"})
    public class ImgServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @Inject
    Screenshot model;
        @PersistenceUnit(unitName = "primary")
    private EntityManagerFactory emf; 

    public ImgServlet() {
        super();
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        PrintWriter writer = response.getWriter();
        ServletContext sc = getServletContext();

        String classString = "Screenshot";
        String idString = request.getParameter("id");

        if (classString == null || classString.isEmpty() || idString == null || idString.isEmpty()) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND); // 404.
            return;
        }

        Long id = Long.parseLong(idString.trim());
        PhotoInterface entry = null;

        EntityManager em = null;

        try {
            em = emf.createEntityManager();
        } catch (Throwable e1) {
            e1.printStackTrace();
        } 

        try {
            entry = em.find(Screenshot.class, id);
        } catch (Exception ex) {
            //Log.log(ex.getMessage());
        }

        if (entry == null) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND); // 404.
            return;
        }

        ServletOutputStream out = null;

        try {
            response.reset();

             // It works ok without setting any of these...
            //response.setContentType(image.getContentType());
            //response.setHeader("Content-Length", String.valueOf(image.getLength()));
            //response.setHeader("Content-Disposition", "inline; filename=\"" + image.getName() + "\"");
            response.setContentType("image/png");

            out = response.getOutputStream();

            if (entry.getPng() != null && entry.getPng().length != 0) {
                out.write(entry.getPng());
                getServletContext().log("Found png!!");
            }
            else 
                getServletContext().log("png is NULL!!!");
        } catch (IOException e) {
            getServletContext().log("Error finding png!!!");
        } finally {
            close(out);
        }

    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

    private static void close(Closeable resource) {
        if (resource != null) {
            try {
                resource.close();
            } catch (IOException e) {
                // Do your thing with the exception. Print it, log it or mail it.
            }
        }
    }
}

contentflow_src.js - Javascript, das zum Rendern des Coverflows verwendet wird, und ein Beispiel finden Sie unter

http://www.jacksasylum.eu/ContentFlow/download.php

Dies funktioniert derzeit in meinem xhtml (ohne ContentFlow Div-Tags im outputPanel):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  
    xmlns:h="http://java.sun.com/jsf/html"  
    xmlns:f="http://java.sun.com/jsf/core"  
    xmlns:p="http://primefaces.org/ui">  

    <ui:composition 
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:a4j="http://richfaces.org/a4j"
                xmlns:rich="http://richfaces.org/rich"
                xmlns:my="http://java.sun.com/jsf/composite/components"
                xmlns:s="http://jboss.com/products/seam/taglib"
                >
    <h:head>  
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <h:outputStylesheet name="screen.css" library="css"/> 
        <script language="JavaScript" type="text/javascript" src="contentflow_src.js" load="slideshow lightbox">
        </script>
    </h:head>  
    <h:body>
       <h:form id="form"> 
        <p:dataTable var="scrshot">
          ....................
          ....................
         </p:dataTable>

          <p:commandButton id="viewDetails" value="View Selected Screenshots" icon="ui-icon-search"  
                             update=":form:imgBlock"/> 

          <p:outputPanel id="imgBlock" layout="block"> 
             <a4j:repeat var="img" value="#{screenshotListProducer.selectedScreenshots}">
               <img src="ImgServlet?id=#{img.id}" title="#{img.time}"/>
             </a4j:repeat>
          </p:outputPanel>
         </h:form>                            
    </h:body> 
    </ui:composition> 
</html>

Dies funktioniert in meinem xhtml nicht (nachdem der ContentFlow durch Umbrechen mit den Div-Tags im outputPanel implementiert wurde) und löst den Fehler aus:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  
    xmlns:h="http://java.sun.com/jsf/html"  
    xmlns:f="http://java.sun.com/jsf/core"  
    xmlns:p="http://primefaces.org/ui">  

    <ui:composition 
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:a4j="http://richfaces.org/a4j"
                xmlns:rich="http://richfaces.org/rich"
                xmlns:my="http://java.sun.com/jsf/composite/components"
                xmlns:s="http://jboss.com/products/seam/taglib"
                >
    <h:head>  
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <h:outputStylesheet name="screen.css" library="css"/> 
        <script language="JavaScript" type="text/javascript" src="contentflow_src.js" load="slideshow lightbox">
        </script>
    </h:head>  
    <h:body>
       <h:form id="form"> 
        <p:dataTable var="scrshot">
          ....................
          ....................
         </p:dataTable>

          <p:commandButton id="viewDetails" value="View Selected Screenshots" icon="ui-icon-search"  
                             update=":form:imgBlock"/> 

          <p:outputPanel id="imgBlock" layout="block"> 
           <div class="ContentFlow" id="ContentFlow">
            <div class="flow">
             <a4j:repeat var="img" value="#{screenshotListProducer.selectedScreenshots}">
              <div class="item">
               <img src="ImgServlet?id=#{img.id}" title="#{img.time}"/>
              </div>
             </a4j:repeat>
            </div>
           </div>
          </p:outputPanel>
         </h:form>                            
    </h:body> 
    </ui:composition> 
</html>

Entschuldigung für den ganzen Code. Wenn jemand helfen kann, wird es sehr geschätzt! Ich habe tagelang versucht, den ContentFlow dazu zu bringen, mit meiner Sitzung gut zu spielen.

Antworten auf die Frage(0)

Ihre Antwort auf die Frage