0

I am trying to implement a scenario where there will be one Upload button and when someone successfully uploads a file that user will be forwarded to the home page.

I have two buttons one to import and another to close the present page and go back to the home page, but I need to include the returning to the home page feature also on the upload button, and return should happen when file is successfully uploaded. I have also implemented error messages for wrong extensions & no file selected, so the return should happen only after a successful file upload.

Please pardon my immaturity here. I am absolutely new in front end development. Please suggest me solutions that can be integrated with .XHTML(JSF) and java Bean as that is the only option I have. Thanks in advance.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
semicoder
  • 1
  • 2

2 Answers2

0

You can you the oncomplete attribute this way:

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://xmlns.jcp.org/jsf/html"
  xmlns:p="http://primefaces.org/ui"
  xmlns:f="http://xmlns.jcp.org/jsf/core">

<h:head>
</h:head>
<f:view>
    <h:form>
        <p:fileUpload fileUploadListener="#{fileUploadView.handleFileUpload}" mode="advanced"
                      oncomplete="window.location='index.xhtml'"
                      update="messages" auto="true" sizeLimit="100000" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />
        <p:growl id="messages" showDetail="true" />
    </h:form>
</f:view>
</html>

With a simple managed bean:

@ManagedBean
public class FileUploadView {

    public void handleFileUpload(FileUploadEvent event) {
        FacesMessage message = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
        FacesContext.getCurrentInstance().addMessage(null, message);
    }
}
Ouerghi Yassine
  • 1,835
  • 7
  • 43
  • 72
0

You can redirect programmatically from your JSF action method, only when every thing goes well.

redirect from jsf?

You can do it in your handleFileUpload method.

Community
  • 1
  • 1
David Mantilla
  • 228
  • 1
  • 10