<p:galleria> <p:graphicimage>未显示所需图像</p:graphicimage> </p:galleria>

时间:2014-02-06 20:28:42

标签: image jsf primefaces galleria

我想使用JSF创建一个图库,所以我尝试了PrimeFaces <p:galleria>

支持bean 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>

结果:

enter image description here

如您所见,图像未显示。这是怎么造成的,我该如何解决?


修改

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

enter image description here

我的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 exception

上给了我for (File f:fList)

1 个答案:

答案 0 :(得分:0)

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

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

并且资源文件夹在编辑的部分

中更正了错误

谢谢你@BalusC

相关问题