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>
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
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);
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 ...
来源:https://stackoverflow.com/questions/8200536/how-to-override-default-file-upload-hmessage-in-icefaces