P:Galleria不显示任何图像



>我正在使用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> 

豆子画廊.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 中

我做错了什么? 我看过素数示例,我的看起来很相似,但运行时没有显示任何内容:(

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

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 未找到错误,但是即使在更改为您的位置后我也得到这个,

我的文件目录是

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 文件夹之外的资源文件夹

图像URL至少非常奇怪。

这里

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

您正在指定完整的 Web 内容相对 URL。

而在这里,

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

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

因此,您的图像URL最终会像

/resources/Tutorial/resources/Tutorial1.jpg

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

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

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:在提交响应后无法创建会话。换句话说,只需升级Mojarra。

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

相关内容

  • 没有找到相关文章

最新更新