【发布时间】:2015-04-12 22:16:18
【问题描述】:
我是 JSF 和 primefaces 的新手。我想在文件上传完成后更新数据网格。我厌倦了更新属性,但它没有更新组件。我只有在重新加载页面后才能看到更新的数据网格。
<h:form>
<p:fileUpload fileUploadListener="#{fileUploadView.handleFileUpload}" mode="advanced" dragDropSupport="false"
multiple="true" update=":content:images" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />
<p:growl id="messages" showDetail="true" />
</h:form>
<h:form id="content">
<p:dataGrid var="image" value="#{dataGridView.images}" columns="2"
rows="12" paginator="true" id="images" rendered="#{not empty dataGridView.images}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="6,12,16" >
<f:facet name="header">
Your Album
</f:facet>
<p:panel header="#{image.imageName}" style="text-align:center;">
<h:panelGrid columns="1" style="width:100%">
<image src="#{image.imageLocation}" style="height: 10%;width:30%;"/>
</h:panelGrid>
</p:panel>
</p:dataGrid>
</h:form>
handleFileUpload 方法
public void handleFileUpload(FileUploadEvent event) {
currentSession.setAttribute("username","sravanyahoo@gmail.com");
String userName = (String) currentSession.getAttribute("username");
String realPath = ctx.getRealPath("/");
String contextPath = ctx.getContextPath();
try{
UploadedFile uploadedFile = event.getFile();
String imageLocation = ImageUtils.uploadFile(realPath,contextPath,uploadedFile,userName);
}
catch(Exception e)
{
}
helper.updateImageList(userName,dataGridView);
FacesMessage message = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
}
updateImageList 方法
public void updateImageList(String userName,DataGridView view){
view.setImages(getImagesFromDB(userName));
}
【问题讨论】:
-
你的
dataGridView.images值是否被fileUploadView.handleFileUpload方法更新了? -
只要更新=":content"
-
是的,handleFileUpload 方法更新“图像”列表
-
刚刚更新:内容不起作用
标签: jsf-2 primefaces