这是我在这里的第一个问题,所以如果我做错了什么,请指出正确的方向。我在尝试在 spring webflow 流中使用基于 uploadify flash 的多文件上传器时遇到了一些困难。以下是该案例的详细说明:
这是我正在使用的库版本:
spring-webflow 2.3.2 spring-web 3.2.1 springwebmvc 3.2.1 Uploadify v3.2 commons-fileupload 1.2.2 commons-io 2.4 commons-codec 1.8 apache tile 3.0.1
网络流配置
<webflow:flow-executor id="flowExecutor">
<webflow:flow-execution-listeners>
<webflow:listener ref="loggingFlowExecutionListener" />
</webflow:flow-execution-listeners>
<!-- max execution sayisina ciktiktan sonra mevcut execution'larin hepsini kill ediyor -->
<webflow:flow-execution-repository max-executions="10" />
</webflow:flow-executor>
<webflow:flow-registry id="flowRegistry" base-path="/WEB-INF/views" flow-builder-services="flowBuilderServices">
<webflow:flow-location-pattern value="/**/*-flow.xml" />
</webflow:flow-registry>
<webflow:flow-builder-services id="flowBuilderServices" view-factory-creator="mvcViewFactoryCreator" development="true" />
<bean id="mvcViewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
<property name="viewResolvers">
<list>
<ref bean="tilesViewResolver" />
</list>
</property>
</bean>
<bean id="loggingFlowExecutionListener" class="com.ilanus.demo.web.config.LoggingFlowExecutionListener" />
流定义
<on-start>
<evaluate expression="advertisementCreationController.initializeAdvertismentForm(flowScope.advForm)" result="flowScope.advForm" />
<evaluate expression="uploadNgController.initializeUploadBean()" result="flowScope.uploadBean"></evaluate>
</on-start>
<view-state id="cadv1" view="cadv1" model="advForm">
<transition on="next" to="cadv2">
<evaluate expression="advertisementCreationController.initializeCriterias(flowScope.advForm)" />
</transition>
<transition on="cancel" to="home" />
</view-state>
<view-state id="cadv2" view="cadv2" model="advForm">
<transition on="previous" to="cadv1" />
<transition on="next" to="cadv3">
<evaluate expression="advertisementCreationController.adjustCheckBoxValues(flowScope.advForm, requestParameters)"></evaluate>
</transition>
<transition on="cancel" to="home" />
</view-state>
<view-state id="cadv3" view="cadv3" model="uploadBean">
<transition on="previous" to="cadv2" />
<transition on="next" to="cadv4" />
<transition on="cancel" to="home" />
</view-state>
现在,在 cadv3 视图上,我有一个 uplodify 集成。所有必需的 js、css 等库都放入页面中,并且有一个 form:form 标签,uploadify 使用它来上传文件。这是 cadv3.jsp:
<div class="createAd2-fileUploadArea">
<form:form modelAttribute="uploadBean" method="POST" enctype="multipart/form-data">
<input id="file-upload" type="file"/>
<input name="dummy" value="someValue" type="text">
</form:form>
<span class="createAd2-startUpload">Yüklemeyi Başlat</span>
</div>
这是初始化uploadify的javascript代码:
$('#file-upload').uploadify(
{
'swf' : fileUploadScriptBaseUrl + '/uploadify.swf',
'uploader' : '/fileUpload',
'multi' : true,
'auto' : false,
'cancelImg' : imageBaseUrl + '/uploadify-cancel.png',
'buttonText' : 'Resim Ekle',
'fileSizeLimit' : '120KB',
'fileTypeExts' : '*.gif; *.jpg; *.jpeg; *.png',
'uploadLimit' : 10,
.
.
.
});
控制器处理 /fileUpload url:
@RequestMapping(value = "/fileUpload", method = RequestMethod.POST)
public @ResponseBody
String Uploadcreate(UploadBean uploadBean, BindingResult result, HttpServletRequest request, HttpServletResponse response,
MultipartRequest multipartRequest) {
System.out.println("started uploading..");
.
.
.
}
和上传豆:
public class UploadBean implements Serializable{
private static final long serialVersionUID = -4487086999401144339L;
private CommonsMultipartFile filedata;
private String name;
private String dummy;
public CommonsMultipartFile getFiledata() {
return filedata;
}
public void setFiledata(CommonsMultipartFile filedata) {
this.filedata = filedata;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDummy() {
return dummy;
}
public void setDummy(String dummy) {
this.dummy = dummy;
}
}
在这里,问题是 UploadBean 的文件数据永远不会被 uploadify 提交填充。它的所有字段都是空的。(虚拟字段仅用于测试目的)使用流范围变量(flowScope.uploadBean)作为表单模型属性值是否错误?或者是否禁止在 webflow 流中进行 ajax 提交(uploadify 调用 ajax 来提交文件输入 AFAIK)?
顺便说一句,我可以在仅弹簧 mvc 的环境中使用 uploadify,如下所述:http://springsourcery.org/springSourcery/content/viewContent,1,32.html?random=4063 可能 我做错了与弹簧有关的事情webflow,所有的帮助将不胜感激,在此先感谢。