我是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));
}
答案 0 :(得分:0)
很可能你的dataGrid在上传和更新之前没有呈现(rendered="#{not empty dataGridView.images}"
。如果确实没有,你会遇到jsf bascis之一,如果没有渲染你就无法更新组件。