p:lightBox mostra una sequenza di foto.
Creare una cartella Web-Inf/resources/images con una immagine chiamata photoProfile.png
Creare i seguenti file:
Photo.java
public class Photo {
private String img;
private String position;
public Photo() {
super();
// TODO Auto-generated constructor stub
}
public Photo(String img, String position) {
super();
this.img = img;
this.position = position;
}
public String getImg() {
return img;
}
public void setImg(String img) {
this.img = img;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
}
GalleriaBean.java
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class GalleriaBean {
private List<Photo> images;
private Photo selectedPlayer;
@PostConstruct
public void init() {
images = new ArrayList<Photo>();
for(int i=1;i<=12;i++) {
Photo photo = new Photo();
photo.setImg(“/resources/images/photoProfile.png”);
photo.setPosition(“http://localhost:8080/JSFProject/resources/images/photoProfile.png”);
images.add(photo);
}
}
public Photo getSelectedPlayer() {
return selectedPlayer;
}
public void setSelectedPlayer(Photo selectedPlayer) {
this.selectedPlayer = selectedPlayer;
}
public List<Photo> getImages() {
return images;
}
public List<Photo> getPlayers() {
return images;
}
}
showPhoto.xhtml
<html 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”
xmlns:c=”http://java.sun.com/jsp/jstl/core”>
<h:head>
</h:head>
<h:body>
<h:form>
<p:lightBox styleClass=”imagebox”>
<ui:repeat var=”image” value=”#{galleriaBean.images}”>
<h:outputLink value=”#{image.position}”>
<p:graphicImage value=”#{image.img}”
alt=”Image Description for #{image}” title=”#{image}” />
</h:outputLink>
</ui:repeat>
</p:lightBox>
</h:form>
</h:body>
</html>