Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override default file upload h:message in ICEfaces

i am using the ace:fileEntry component to upload files and after successful upload i get the message that:

'File Entry' uploaded successfully 'filename'.

and i want to override this message and display other message (some kind of a summary for parsing that uploaded file), any ideas how ?

here's my code:

<h:form>
        <ace:fileEntry id="fileEntryComp"
               label="File Entry"
               relativePath="uploaded"
               fileEntryListener="#{mybean.uploadFile}"/> 



        <h:commandButton value="Upload Excel File" />
        <h:message for="fileEntryComp" />         

    </h:form>
like image 411
Mahmoud Saleh Avatar asked Nov 20 '11 09:11

Mahmoud Saleh


3 Answers

The fileEntry.getResults().getFiles() gives you an ArrayList of FileInfo objects. If you upload only one file, you can get the FileInfo the following way:

FileInfo fileInfo = fileEntry.getResults().getFiles().get(0);

You should call the updateStatus method of the FileInfo the following way to override the default message:

fileInfo.updateStatus(new FileEntryStatus() {
    @Override
    public boolean isSuccess() {
        return true;
    }
    @Override
    public FacesMessage getFacesMessage(FacesContext facesContext,
            UIComponent fileEntry, FileEntryResults.FileInfo fi) {
        return new FacesMessage(FacesMessage.SEVERITY_INFO,
                "My success message: " + fi.getFileName(),
                "My success message: " + fi.getFileName());
    }
}, true, true);
like image 133
Donato Szilagyi Avatar answered Nov 15 '22 07:11

Donato Szilagyi


You have to create your own message and send it. It will overwrite the default message. Its a strange behavior but it will work.

public void uploadFile(FileEntryEvent e) {
  FileEntry fe = (FileEntry)e.getComponent();

  FacesContext ctx = FacesContext.getCurrentInstance();
  FacesMessage msg = new FacesMessage();
  msg.setServity(FacesMessage.SERVITY_INFO);
  msg.setSummary("mysummary");
  msg.setDetail("mydetail");
  ctx.addMessage(fe.getClientId(),msg);
}

You can check the showcase: http://comp-suite.icefaces.org/comp-suite/showcase.jsf?grp=aceMenu&exp=fileEntry

like image 45
Udo Held Avatar answered Nov 15 '22 06:11

Udo Held


You can override icefaces messages.

Default message bundle (just to know which message to ovverride) can be found in icefaces source package:

     icefaces3/ace/component/src/org/icefaces/ace/resources/messages.properties

where:

     org.icefaces.ace.component.fileEntry.SUCCESS          = ''{0}'' has successfully uploaded ''{1}''
     org.icefaces.ace.component.fileEntry.SUCCESS_detail   = ''{0}'' has successfully uploaded ''{1}''

and these are lines I put in my application.properties file:

    org.icefaces.ace.component.fileEntry.SUCCESS          = File ''{1}'' caricato correttamente
    org.icefaces.ace.component.fileEntry.SUCCESS_detail   = File ''{1}'' caricato correttamente

be sure to have application.properties defined in faces-config.xml and visible by you application:

<application>
    <message-bundle>application</message-bundle>
    <locale-config>
        <default-locale>en</default-locale>
    </locale-config>
</application>

This can be done with all Icefaces default messages ...

like image 37
venusoft Avatar answered Nov 15 '22 06:11

venusoft