How to take the refresh of the whole page when using the FileUpload component of the firstfaces

6

I'm using the FileUpload component of primefaces in mode="simple" and it works fine. But when I click the save button on a particular folder, it refreshes the entire page. Can you take it?

Below is my XHTML code:

 <h:form enctype="multipart/form-data" id="form"><p:messages id="messages" showDetail="true" autoUpdate="true"
            closable="true" />
    <h:panelGrid columns="1" cellpadding="2" style="font-size: 10px" id="panelGrid1">
        <h:panelGroup id="panelGroup1" >
            <p:outputLabel for="nomeTexto" value="Nome do Texto: " rendered="#{parametrizacaoTagsControl.tipoTag == 1}" />
            <p:inputText id="nomeTexto"
                value="#{parametrizacaoTagsControl.nomeTexto}" rendered="#{parametrizacaoTagsControl.tipoTag == 1}" />

            <p:fileUpload value="#{parametrizacaoTagsControl.file}"
                mode="simple" skinSimple="true" rendered="#{parametrizacaoTagsControl.tipoTag == 2}" label="Escolher arquivo"/>
        </h:panelGroup>

        <p:separator />
        <h:panelGrid columns="4" cellpadding="2" style="font-size: 10px"  id="panelGrid2" >
            <p:commandButton value="Incluir" ajax="false"
                actionListener="#{parametrizacaoTagsControl.upload}"
                disabled="#{!parametrizacaoTagsControl.habilitaBotoes}" />
        </h:panelGrid>
    </h:panelGrid>

</h:form>
    
asked by anonymous 15.04.2015 / 18:54

1 answer

1

The only way you can maintain the status of the page (without refresh) when making a submit is via AJAX . There is no ajax attribute in the p:fileUpload component. To enable ajax you should change the mode="simple" (without ajax) to mode="advanced" (with ajax) and add the fileUploadListener attribute.

Here's how:

1 - Add the method to receive the file in your ParametrizacaoTagsControl ed bean:

public void handleFileUpload(FileUploadEvent event) throws IOException {
        file = event.getFile();
}

2 - Change your p:fileUpload :

<p:fileUpload fileUploadListener="#{parametrizacaoTagsControl.handleFileUpload}" 
    rendered="#{parametrizacaoTagsControl.tipoTag == 2}" mode="advanced" 
    update="fileContainer" label="Escolher arquivo" />

<h:panelGroup id="fileContainer" layout="block">
   <ui:fragment rendered="#{parametrizacaoTagsControl.file!=null}">
       <p>Nome do arquivo: #{parametrizacaoTagsControl.file.fileName}</p>
    </ui:fragment>
</h:panelGroup>

I'm using h:panelGroup just to see ajax in action. Pay close attention to the update attribute because it is where you tell what will be updated.

    
25.04.2017 / 03:34