我在PrimeFaces中为p:galleria
实现了这个示例。我可以毫无问题地显示我的图像等。但我希望每张图片都有自己的标题。这是我的代码:
<p:galleria value="#{mywork.images}" var="image" panelWidth="500" panelHeight="313"
showCaption="true" style="left:350px;">
<p:graphicImage name="/galleria/dotacion/#{image}" alt="Image Description for #{image}"
title="#{mywork.titles}" style="width:100%;"/>
</p:galleria>
这是我的豆子:
package org.portfolio.util;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
@ManagedBean
public class Mywork {
private List<String> images;
private String titles = "";
private String titles2 = "";
@PostConstruct
public void init() {
images = new ArrayList<String>();
for (int i = 1; i <= 7; i++) {
images.add("pierrel"+i+".jpg");
if (i == 1) {
titles = "imagen de prueba if1";
getTitles();
}
if (i == 2){
titles = "imagen de prueba if2";
getTitles();
}
}
}
public List<String> getImages() {
return images;
}
public String getTitles() {
return titles;
}
public String getTitles2() {
return titles2;
}
}
我做错了什么或错过了什么?
这只是为每张图片返回“imagen de prueba if2”。
答案 0 :(得分:0)
您可以使用Object而不是使用字符串列表。
在你的ManagedBean
中@ManagedBean
public class Mywork {
private List<ImageObject> images;
@PostConstruct
public void init() {
images = new ArrayList<String>();
for (int i = 1; i <= 7; i++) {
images.add(new ImageObject("fileName" + i + ".jpg", "myDescription", "myTitle"));
}
}
public class ImageObject{
private String fileName;
private String description;
private String title;
public ImageObject(String fileName, String description, String title){
this.fileName = fileName;
this.description = description;
this.title = title;
}
//Getters setters
}
}
你的xhtml中的
<p:galleria value="#{mywork.images}" var="image" panelWidth="500" panelHeight="313" showCaption="true" style="left:350px;">
<p:graphicImage name="/galleria/dotacion/#{image.fileName}" alt="#{image.description}" title="#{image.title}" style="width:100%;"/>
</p:galleria>