How to override default file upload h:message in ICEfaces
Asked Answered
S

3

7

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>
Serge answered 20/11, 2011 at 9:11 Comment(0)
S
3

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

Sanfordsanfourd answered 20/11, 2011 at 9:19 Comment(7)
what about if i am working with FileEntryCallBack instance as in here: wiki.icefaces.org/display/ICE/… and i want in the end message to add a summary message ?Serge
We haven't used that one yet, so I cannot tell.Sanfordsanfourd
ah found it in the full tutorial here: wiki.icefaces.org/display/ICE/…Serge
well there's a case, i shows the new message beside the button, and it keeps showing the old default message but out of the form !!!!Serge
IIRC we were using ice:form and ice:messages, however I'm not sure if that makes a difference.Sanfordsanfourd
@UdoHeld: How to get rid of default message that is being popped out from fileEntry Component?Tartarus
'File Entry' has successfully uploaded 'test.xml'Tartarus
T
5

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);
Temptress answered 13/12, 2012 at 9:16 Comment(0)
S
3

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

Sanfordsanfourd answered 20/11, 2011 at 9:19 Comment(7)
what about if i am working with FileEntryCallBack instance as in here: wiki.icefaces.org/display/ICE/… and i want in the end message to add a summary message ?Serge
We haven't used that one yet, so I cannot tell.Sanfordsanfourd
ah found it in the full tutorial here: wiki.icefaces.org/display/ICE/…Serge
well there's a case, i shows the new message beside the button, and it keeps showing the old default message but out of the form !!!!Serge
IIRC we were using ice:form and ice:messages, however I'm not sure if that makes a difference.Sanfordsanfourd
@UdoHeld: How to get rid of default message that is being popped out from fileEntry Component?Tartarus
'File Entry' has successfully uploaded 'test.xml'Tartarus
N
2

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 ...

Nevels answered 20/7, 2012 at 14:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.