使用 s:fileUpload 组件,如下面 .xhtml 文件的片段
用于 JSF 数据的后台绑定 Bean,Seam 组件名为 fileUploadItem,点击 h:commandButton 时会触发
#{fileUploadItem.process} 方法,执行正确的话返回 success 字符串,失败的话返回 failed,具体
的页面导向在 .page.xml 文件中配置 navigation 的导航规则。
-
XML code
-
< s:fileUpload data ="#{fileUploadItem.data}" required ="true" requiredMessage ="请导入" contentType ="#{fileUploadItem.contentType}" fileName ="#{fileUploadItem.fileName}" accept ="text/plain" /> < h:commandButton id ="save" value ="确定" action ="#{fileUploadItem.process}" />
用于 JSF 数据的后台绑定 Bean,Seam 组件名为 fileUploadItem,点击 h:commandButton 时会触发
#{fileUploadItem.process} 方法,执行正确的话返回 success 字符串,失败的话返回 failed,具体
的页面导向在 .page.xml 文件中配置 navigation 的导航规则。
-
Java code
-
@Name( " fileUploadItem " ) public class FileUploadItem { private String contentType; private String fileName; private byte [] data; public String process() { // 处理 data 这个字节数组就行了。 return " success " ; } getter / setter... }