Primefaces FacesMessage not displaying from FileUploadEvent

UI Components for JSF
Post Reply
cgswtsu78
Posts: 53
Joined: 25 Jan 2011, 19:18

12 Mar 2011, 01:11

Hello,

Has anyone ever been able to get a FacesMessage to appear when one is added in the FileUploadEvent? I'm unable to do so...

Code: Select all

<p:dialog header="#{bundle['dreamUpload.HEADER']}"
    widgetVar="dreamUploadDlg" modal="true" styleClass="dialog dialog2"
    draggable="false" resizable="false" showEffect="fade"
    hideEffect="fade">
    <div class="dialog-top-reg"></div>
    <div class="dialog-middle-reg">
        <div class="close-button">
            <h:form>
                <p:commandButton onclick="dreamUploadDlg.hide()" />
            </h:form>
        </div>
        <h:form class="dialog-content dialog-content2">
            <h1 class="upload-dream">
                <h:outputText value="#{bundle['dreamUpload.HEADER']}" />
            </h1>
            <p class="upload-dream">
                <h:outputText value="#{bundle['dreamUpload.SUBHEADER']}" />
            </p>
            <div class="upload-dream-wrap">
                <fieldset>
                    <p:inputText />
                    <p:growl id="messages" showSummary="true" showDetail="true" />
                    <p:fileUpload fileUploadListener="#{dreamFileUpload.handleFileUpload}" auto="true"  
                            allowTypes="*.jpg;*.png;*.gif;" description="Images"/> 
                </fieldset>
                <h:outputText class="requirements"
                    value="#{bundle['dreamUpload.upload.requirements.TEXT']}" />
            </div>
        </h:form>
    </div>
    <div class="dialog-bottom-reg"></div>
</p:dialog>
public void handleFileUpload(FileUploadEvent event) {
String path="/users/cgray/fileupload";
//new File(path + "/" + album.getId()).mkdirs();
File result = new File(path + "/" + event.getFile().getFileName());

try {
FileOutputStream fileOutputStream = new FileOutputStream(result);

byte[] buffer = new byte[512000]; //50kb

int bulk;
InputStream inputStream = event.getFile().getInputstream();
while (true) {
bulk = inputStream.read(buffer);
if (bulk < 0) {
break;
}
fileOutputStream.write(buffer, 0, bulk);
fileOutputStream.flush();
}

fileOutputStream.close();
inputStream.close();

FacesMessage msg = new FacesMessage("Succesful",
event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);


} catch (IOException e) {
e.printStackTrace();
FacesMessage error = new FacesMessage("The files were not uploaded!");
FacesContext.getCurrentInstance().addMessage(null, error);
}
}

public void close(CloseEvent e){

}
}

Code: Select all



judadiso
Posts: 1
Joined: 28 Aug 2018, 22:51

28 Jan 2019, 15:46

Good Day

I have the same problem. maybe did you find any solution about it?

Thanks

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

28 Jan 2019, 18:32

Hi, maybe you can create a better example with what you tried? Then we might be able to see what is wrong or can use that as a basis for trying to fix it

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 23 guests