Search code examples
javajsffile-uploadicefaces

Configuring JSF/ICEFaces InputFile programmatically


I have an InputFile isntance put on my form from Java code like this:

FacesContext context = FacesContext.getCurrentInstance();

MethodExpressionActionListener meal = new MethodExpressionActionListener(context.getApplication().getExpressionFactory().createMethodExpression(context.getELContext(), "#{mybackingbean.fileUploadEvent}", null,
        new Class[] { ActionEvent.class }));

InputFile inputFile = new InputFile();
inputFile.setAutoUpload(false);
inputFile.addActionListener(meal);
//inputFile.setActionExpression(...) - did not work
//inputFile.setAction(..) - did not work

parent.getChildren().add(inputFile);

The component renders correctly, after clicking the upload button the browser sends the POST request but my backing bean is never notified. I tried the similar-looking setActionExpression and setAction methods as well to bind the component to my bean but nothing happens.

Do you have any ideas how to make my backing bean aware of the file upload outcome..?

Updated

Switching on more logging I can see that the file is uploaded and this is logged:

2011-12-07 22:12:54,097 UploadServer DEBUG - UploadServer  doLifecycle :: Window00303:j_id117 in form 'Window00303' -> FileInfo: {
  percent=100,
  preUpload=false,
  postUpload=false,
  exception=null,
  fileName=abcchmvw.INI,
  file=[...],
  physicalPath=[...],
  contentType=application/octet-stream,
  size=437,
  status=2
}

I decompiled the UploadServer but can't see the reason why my actionListener should be called.


Solution

  • The solution is addActionListener but the important thing that failed all was not setting an id for the component via calling setId()