Question

I'd like to create an image gallery using JSF, so I tried the PrimeFaces <p:galleria>.

The backing 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;
    }
}

The view 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>

The result:

enter image description here

As you see, the images don't show up. How is this caused and how can I solve it?


EDIT:

now my resources folder is like this :

enter image description here

and my gallery.xhtml is :

<!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>

but it gives me null pointer exception on for (File f:fList)

Was it helpful?

Solution

i wanted to accept @BalusC answer but i don't know why he deleted the answer

as you can see in the edited part , the .xhtml format was wrong (the true .xhtml part is in edited part)

and also the resources folder was wrong that it corrected in edited part

thank you @BalusC

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top