java - ajaxform not submit the value if attachment is not available -
i beginner in java , go create 1 web application. submitting 1 form controller using ajaxform. there few elements , 1 of them type=file
.
my controller method following
@requestmapping(value = { "/addreplies" }, method = { org.springframework.web.bind.annotation.requestmethod.post, org.springframework.web.bind.annotation.requestmethod.get } ) @responsebody public map<string,object> addreplies( @valid @modelattribute("replies") replies replies, bindingresult result, httpservletrequest request, httpservletresponse response,locale locale,principal principal, @requestparam(value = "filedata2",required=false) commonsmultipartfile filedata2[]) throws servletexception, ioexception { //perform opraton }
this work if there attachment available in data otherwise not go method.
if remove @requestparam(value = "filedata2",required=false) commonsmultipartfile filedata2[]
parameter method work way cannot attachment.
please try understand question , give me possible solution.
this method working if not using ajax , submit form regul
for uploading file need use enctype="multipart/form-data" in form. if want use ajax upload file, along simple ajax call need use methods
or
whey uploading file, before serialize ajaxform first check filepart null or not, if null disable element longer availability , submit
beforeserialize: function($form, options){ //before serializing data have disable element if data not avaliable $(".attachfile").filter(function(){ return !this.value; }).attr("disabled", "disabled"); },
Comments
Post a Comment