Question

this is my first question here so please point me to right direction if i do something wrong. i'm experiencing some difficulties while trying to use uploadify flash based multi file uploader inside a spring webflow flow. here is a detailed explanation of the case:

here is the versions of libraries i'm using:

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 tiles 3.0.1

webflow conf

    <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" />

flow definition

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

now, on cadv3 view i have an uplodify integration. all required js, css etc libraries put into the page and there is a form:form tag which is used by uploadify to upload files. here is 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>

and here is javascript code to initialize uploadify:

            $('#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,
                    .
                    .
                    .
        });

the controller handing /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..");
    .
    .
    .
}

and UploadBean:

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

}

here, the problem is filedata of the UploadBean never gets populated by uploadify submits. It's all fields are just null. (dummy field is there just for testing purposes) Is it wrong using a flow scoped variable(flowScope.uploadBean) as form modelAttribute value? Or is it forbidden to have ajax submits(uploadify makes ajax calls to submit file inputs AFAIK) inside a webflow flow?

by the way i can use uploadify in a spring mvc only environment as described here: http://springsourcery.org/springSourcery/content/viewContent,1,32.html?random=4063 probably i'm doing something wrong related to spring webflow, all the helps would be appreciated, thanks in advance.

Was it helpful?

Solution

solved the issue, it was due to another multipart configuration, like this:

i have implemented WebApplicationInitializer interface to initialize my web application(ie no web.xml), inside this implementation there was a line

dispatcher.setMultipartConfig(new MultipartConfigElement(null, MAX_FILE_UPLOAD_SIZE, MAX_REQUEST_SIZE, FILE_SIZE_THRESHOLD));

this MultipartConfigElement(from javax.servlet package) was setting some size limits, and it somehow disturbed spring's file upload mechanism. i think it's something related to: Apache commons fileupload FileItemIterator hasNext() returns false

look at balusC's comment on second(accepted) answer. anyway, after commenting out above line it works as expected. hope this helps somebody, thanks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top