我是JSF和primefaces的新手。我想在文件上傳完成時更新數據網格。我累更新屬性,但它沒有更新組件。我只能在重新加載頁面後才能看到更新的數據網格。無法使用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","[email protected]");
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'方法更新? – 2015-02-12 09:01:49
只是做更新=「:內容」 – 2015-02-12 10:18:17
是的,handleFileUpload方法更新「圖像」列表 – user3173392 2015-02-12 10:43:56