【发布时间】:2013-03-26 06:02:36
【问题描述】:
参考:http://www.primefaces.org/showcase/ui/galleria.jsf
我的页面:
<p:galleria id="merchant-gallery" value="#{testController.imageIds}" var="item" autoPlay="false" >
<p:graphicImage width="300" value="#{imageStreamer.image}" >
<f:param name="id" value="#{item}" />
</p:graphicImage>
</p:galleria>
我尝试将<p:galleria> 包含在一个表单中并添加了一个<p:remoteCommand name="updateme" update="@form"/>,但在调用updateme 之后它只是将galleria 设为空白。
*更新
testController bean:
public List<Integer> getImageIds() {
int aId = (Integer) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("user_id");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("TEST2PU");
EntityManager em = emf.createEntityManager();
TypedQuery<Merchant> tp = em.createQuery("SELECT a FROM Account a WHERE a.id = :id", Account.class);
tp.setParameter("id", aId);
current = tp.getSingleResult();
Collection rawPhotoCollection = current.getPhotoCollection();
imageIds = new ArrayList<Integer>(rawPhotoCollection);
List<Photo> photoList = new ArrayList<Photo>(rawPhotoCollection);
for (int i = 0; i < photoList.size(); i++) {
int imageId = photoList.get(i).getId();
imageIds.set(i, imageId);
}
return imageIds;
}
imageStreamer bean:
@EJB
private test.controller.photo.PhotoFacade ejbFacade;
public StreamedContent getImage() throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
return new DefaultStreamedContent();
} else {
Map<String, String> param = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
String id = param.get("id");
Photo image = ejbFacade.find(Integer.valueOf(id));
return new DefaultStreamedContent(new ByteArrayInputStream(image.getImage()));
}
}
【问题讨论】:
-
你想达到什么目的?
-
我有一个
<p:fileUpload>功能,上传每张图片后我想重新加载画廊而不刷新页面。 -
你能发布一些bean代码吗?您确定上传后图像在那里并且 .imageIds 不为空吗?
-
嗨@roel我用bean代码更新了问题,是的,我确定上传后imageids不是空的,因为我尝试调试代码,它仍然返回列表ids 但它不会再渲染广场了,只是空白。
-
所以你从你的
调用 updateme?我想您的 javascript 控制台中没有任何错误?还是在您的服务器控制台中?您的画廊在面板或对话框内吗?首次访问页面,gallery 显示是否正确?您使用什么浏览器以及什么版本的 primefaces?
标签: jsf primefaces