0

I am new to JSF and primefaces.I want to updated data grid when file upload completes. i tired update attribute but it did not update component. i could see updated data grid only after reloading the page.

<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 method

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 method

public void updateImageList(String userName,DataGridView view){       
        view.setImages(getImagesFromDB(userName));
    }

1 Answers1

0

Most likely your dataGrid is not rendered before the upload and update (rendered="#{not empty dataGridView.images}". If it is indeed not, you are running into one of jsf bascis that you cannot update a component if it is not rendered.

Community
  • 1
  • 1
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • I had removed rendered and tried, but it didn't worked – user3173392 Feb 12 '15 at 10:44
  • Then look at the comment above by @AlexandreLavoie. And what version are you using? And what is the scope of the bean? And maybe try with an ajax eventHandler. Should not make a difference, but you never know – Kukeltje Feb 12 '15 at 10:52