How to override default file upload h: message in ICEfaces

I use the ace: fileEntry component to download files and after a successful download I get a message that:

'File Entry' uploaded successfully 'filename'. 

and I want to redefine this message and display another message (some kind of summary for parsing this downloaded file), any ideas how?

here is 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> 
+6
source share
3 answers

You need to create your own message and send it. It will overwrite the default message. This is a weird 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

+3
source

File Entry.getResults (). getFiles () gives you an ArrayList of FileInfo objects. If you upload only one file, you can get FileInfo as follows:

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

You must call the updateStatus method for FileInfo as follows 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); 
+4
source

You can override ice messages.

The default message package (only to find out which message is for ovverride) can be found in the original icefaces 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 the lines that I put in the application.properties file:

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

make sure application.properties is defined in faces-config.xml and visible by your application:

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

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

+2
source

Source: https://habr.com/ru/post/901929/


All Articles