How to override default file upload h:message in ICEfaces

半世苍凉 提交于 2019-12-07 01:32:31

问题


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>

回答1:


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




回答2:


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);



回答3:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!