1

我正在使用 primefaces p:galleria 来显示一些图像,但是它根本没有显示任何东西,

                <p:galleria value="#{galleriaBean.images}" 
                            var="image" 
                            effect="slide" 
                            effectSpeed="1000"
                            panelWidth="500" 
                            panelHeight="313" 
                            showCaption="false">  

                    <p:graphicImage value="/resources/Tutorial/#{image}" 
                                    alt="Image Description for #{image}" 
                                    title="#{image}"/>  
                </p:galleria> 

GalleriaBean.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package richard.fileupload;

import java.util.ArrayList;  
import java.util.List;  
import javax.annotation.PostConstruct; 
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;
/**
 *
 * @author Richard
 */

@ManagedBean(name="galleriaBean")
//@RequestScoped
@ViewScoped

public class GalleriaBean {  

    public static List<String> images;  


    @PostConstruct  
    public void init() {  
        System.out.println("init called");
        images = new ArrayList<String>();  

        for(int i=1;i<=25;i++) {  
            images.add("/resources/Tutorial"+i+".jpg");
        }  
    }  

    public List<String> getImages() {  
        return images;  
    }

}

图像存储在 /resources/Tutorial

我究竟做错了什么 ?我查看了 primefaces 示例,我的看起来相似,但运行时没有显示任何内容:(

我现在得到这个巨大的错误:

INFO: init called

    WARNING: Setting non-serializable attribute value into ViewMap: (key: galleriaBean, value class: richard.fileupload.GalleriaBean)
    SEVERE: Error Rendering Vi

ew[/GUI/tutorial.xhtml]
    java.lang.IllegalStateException: PWC3999: Cannot create a session after the response has been committed
        at org.apache.catalina.connector.Request.doGetSession(Request.java:2886)
        at org.apache.catalina.connector.Request.getSession(Request.java:2583)
        at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:920)
        at com.sun.faces.context.ExternalContextImpl.getSession(ExternalContextImpl.java:155)
        at com.sun.faces.renderkit.ServerSideStateHelper.writeState(ServerSideStateHelper.java:175)
        at com.sun.faces.renderkit.ResponseStateManagerImpl.writeState(ResponseStateManagerImpl.java:122)
        at com.sun.faces.application.StateManagerImpl.writeState(StateManagerImpl.java:166)
        at com.sun.faces.application.view.WriteBehindStateWriter.flushToWriter(WriteBehindStateWriter.java:225)
        at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:419)
        at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
        at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
        at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
        at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
        at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
        at java.lang.Thread.run(Thread.java:722)

    INFO: Exception when handling error trying to reset the response.
    java.lang.IllegalStateException: PWC3999: Cannot create a session after the response has been committed
        at org.apache.catalina.connector.Request.doGetSession(Request.java:2886)
        at org.apache.catalina.connector.Request.getSession(Request.java:2583)
        at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:920)
        at com.sun.faces.context.ExternalContextImpl.getSession(ExternalContextImpl.java:155)
        at com.sun.faces.renderkit.ServerSideStateHelper.writeState(ServerSideStateHelper.java:175)
        at com.sun.faces.renderkit.ResponseStateManagerImpl.writeState(ResponseStateManagerImpl.java:122)
        at com.sun.faces.application.StateManagerImpl.writeState(StateManagerImpl.java:166)
        at com.sun.faces.application.view.WriteBehindStateWriter.flushToWriter(WriteBehindStateWriter.java:225)
        at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:419)
        at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
        at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
        at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
        at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
        at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
        at java.lang.Thread.run(Thread.java:722)

    WARNING: JSF1087: Unable to generate Facelets error page as the response has already been committed.
    SEVERE: javax.faces.FacesException: PWC3999: Cannot create a session after the response has been committed
    javax.faces.FacesException: PWC3999: Cannot create a session after the response has been committed
        at com.sun.faces.context.ExceptionHandlerImpl.handle(ExceptionHandlerImpl.java:142)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
        at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
        at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
        at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
        at java.lang.Thread.run(Thread.java:722)
    Caused by: java.lang.IllegalStateException: PWC3999: Cannot create a session after the response has been committed
        at org.apache.catalina.connector.Request.doGetSession(Request.java:2886)
        at org.apache.catalina.connector.Request.getSession(Request.java:2583)
        at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:920)
        at com.sun.faces.context.ExternalContextImpl.getSession(ExternalContextImpl.java:155)
        at com.sun.faces.renderkit.ServerSideStateHelper.writeState(ServerSideStateHelper.java:175)
        at com.sun.faces.renderkit.ResponseStateManagerImpl.writeState(ResponseStateManagerImpl.java:122)
        at com.sun.faces.application.StateManagerImpl.writeState(StateManagerImpl.java:166)
        at com.sun.faces.application.view.WriteBehindStateWriter.flushToWriter(WriteBehindStateWriter.java:225)
        at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:419)
        at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
        at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
        at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        ... 31 more

但初始化被称为:D

编辑:现在把它降低到 1 个错误:

WARNING: Setting non-serializable attribute value into ViewMap: (key: galleriaBean, value class: richard.fileupload.GalleriaBean)

当前代码:现在没有错误,但也没有显示任何内容

  /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package richard.fileupload;

import java.io.Serializable;
import java.util.ArrayList;  
import java.util.List;  
import javax.annotation.PostConstruct; 
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
/**
 *
 * @author Richard
 */

@ManagedBean(name="galleriaBean")
//@RequestScoped
@ViewScoped

public class GalleriaBean implements Serializable {  

    public static List<String> images;  


    @PostConstruct  
    public void init() {  
        FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        System.out.println("init called"); //testing to see if it called, currently causing a lot of errors
        images = new ArrayList<String>();  

        for(int i=1;i<=3;i++) {  
             System.out.println("loop called"); //testing to see if it called, currently causing a lot of errors
            images.add("/resources/Tutorial/"+ i +".jpeg");
        }  
    }  

    public List<String> getImages() {  
        System.out.println("getImages called"); //testing to see if it called, currently causing a lot of errors
        return images;  
    }

}

控制台:

INFO: init called
INFO: loop called
INFO: loop called
INFO: loop called
INFO: getImages called

所有都被调用,但仍然没有显示

编辑 :

感谢您的帮助,我已经按照您的建议更改了文件位置并检查了 chrome 中的控制台,您是对的,我收到 404 not found 错误,但是即使更改到您的位置后我也得到了这个,

我的文件目录是

WebContent
 |-- META-INF
 |-- WEB-INF
 |-- GUI
 |    `-- tutorial.xhtml (page calling the images)
 |-- resources
 |    `-- Tutorial
 |         |-- Tutorial1.jpg
 |         |-- Tutorial2.jpg
 |         |-- Tutorial3.jpg
 |         :   :
 |

但是使用 chromes 控制台,我可以看到它正在尝试在其中找到图像,/fileuploadWithPreview//GUI/Tutorial/Tutorial但它们存储在resources/tutorial/

新问题是我如何让它调用 xhtml 文件所在的 GUI 文件夹之外的资源文件夹

4

1 回答 1

4

图片 URL 至少很奇怪。

这里,

for(int i=1;i<=25;i++) {  
    images.add("/resources/Tutorial"+i+".jpg");
}

您正在指定完整的 webcontent-relative URL。

和这里,

<p:graphicImage value="/resources/Tutorial/#{image}" ... />

您假设图像 URL 是相对于/resources/Tutorial.

因此,您的图片网址最终会像

/resources/Tutorial/resources/Tutorial1.jpg

两次/resources?这似乎不对。如果您在 webbrowser 的开发人员工具集中注意 HTTP 流量(在 Chrome/IE9/Firebug 中按 F12),那么您应该注意到浏览器在所有这些图像上都收到 404 Page Not Found 错误。此外,如果您注意src生成的 HTML<img>元素,您应该注意到有些地方不对劲。

假设您在文件夹中有Tutorial[n].jpg图像,/resources/Tutorial

WebContent
 |-- META-INF
 |-- WEB-INF
 |-- resources
 |    `-- Tutorial
 |         |-- Tutorial1.jpg
 |         |-- Tutorial2.jpg
 |         |-- Tutorial3.jpg
 |         :   :
 |
 `-- page.xhtml

那么您应该按如下方式准备图像文件名:

for(int i=1;i<=25;i++) {  
    images.add("Tutorial"+i+".jpg");
}

并按如下方式引用它们(注意:name,不是value!)

<p:graphicImage name="Tutorial/#{image}" ... />

至于 PWC3999 例外,这是一个完全不同的问题。如何解决,看一下添加 <h:form> 导致 java.lang.IllegalStateException: Cannot create a session after the response has beencommited。换句话说,只需升级 Mojarra。

至于不可序列化的属性警告,只要让提到的类实现Serializable

于 2013-02-03T20:26:04.963 回答