【问题标题】:<p:galleria><p:graphicImage> doesn't show the desired images<p:galleria><p:graphicImage> 未显示所需的图像
【发布时间】:2014-02-06 20:28:41
【问题描述】:

我想使用 JSF 创建一个图片库,所以我尝试了 PrimeFaces &lt;p:galleria&gt;。

后台豆galley.java:

@ManagedBean
public class galley {
private List<String>list;
@PostConstruct
public void init(){
    list=new ArrayList<String>();
    File file=new File("/home/user/Pictures/wallpaper/batman");
    File[]fList=file.listFiles();
    for (File f:fList){
        if (f.getName().endsWith("jpg"))
            list.add(f.getAbsolutePath());
    }
}

public List<String> getList() {
    return list;
    }
}

观点gallery.xhtml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:p="http://primefaces.org/ui">

<p:galleria value="#{galley.list}" var="image" panelWidth="500"  panelHeight="313" showCaption="true">
<p:graphicImage value="#{image}" alt="Image Description for #{image}" title="#{image}"/>
</p:galleria>
</html>

结果:

如您所见,图像不显示。这是如何引起的,我该如何解决?


编辑:

现在我的资源文件夹是这样的:

我的gallery.xhtml 是:

<!DOCTYPE html>
<html lang="en"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:p="http://primefaces.org/ui"
    >
 <h:head>
   <title>gallery</title>
 </h:head>
 <h:body>
    <p:galleria value="#{galley.list}" var="image" panelWidth="500" panelHeight="313" showCaption="true">
    <p:graphicImage value="resources/images/#{image}" alt="Image Description for #{image}" title="#{image}"/>
</p:galleria>
</h:body>

但它给了我null pointer exceptionfor (File f:fList)

【问题讨论】:

  • Value 属性采用 Binary data to stream or context relative path 根据 Primefaces 文档而不是图像的绝对路径。
  • 感谢@SRy,即使/home/user/Pictures/wallpaper/batman/#{image} 也不起作用
  • 为什么不直接按照Primefaces showcase 来实现这个简单的要求。 primefaces.org/showcase/ui/galleria.jsf

标签: image jsf primefaces galleria


【解决方案1】:

我想接受@BalusC 的答案,但我不知道他为什么删除了答案

正如您在编辑部分中看到的那样,.xhtml 格式错误(真正的 .xhtml 部分在编辑部分中)

而且资源文件夹是错误的,它在编辑部分更正了

谢谢@BalusC

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-16
    • 2011-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-21
    • 2016-05-22
    • 1970-01-01
    相关资源
    最近更新 更多