简体   繁体   English

以编程方式配置JSF / ICEFaces InputFile

[英]Configuring JSF/ICEFaces InputFile programmatically

I have an InputFile isntance put on my form from Java code like this: 我从Java代码中将一个InputFile象差放在我的表单上,如下所示:

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. 单击上载按钮后,该组件将正确呈现,浏览器发送了POST请求,但从未通知我的后备bean。 I tried the similar-looking setActionExpression and setAction methods as well to bind the component to my bean but nothing happens. 我也尝试过使用外观类似的setActionExpressionsetAction方法将组件绑定到我的bean,但是什么也没有发生。

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. 我反编译了UploadServer但看不到应调用我的actionListener的原因。

解决方案是addActionListener但是所有失败的重要事情不是通过调用setId()为组件设置id。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM