以编程方式配置JSF / ICEFaces InputFile

时间:2011-12-06 21:39:54

标签: java jsf file-upload icefaces

我从Java代码中将一个InputFile isntance放在我的表单上,如下所示:

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

组件正确呈现,在单击上传按钮后,浏览器发送POST请求,但我的支持bean从未得到通知。我尝试了类似外观的setActionExpressionsetAction方法,将组件绑定到我的bean但没有任何反应。

您是否有任何想法如何让我的支持bean知道文件上传结果..?

更新

开启更多日志记录我可以看到文件已上传并记录下来:

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
}

我反编译了UploadServer,但看不出应该调用actionListener的原因。

1 个答案:

答案 0 :(得分:0)

解决方案是addActionListener但是失败的重要一点是没有通过调用setId()

为组件设置ID