DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26639>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26639

Multipart request parameters lost after validation failure

           Summary: Multipart request parameters lost after validation
                    failure
           Product: Struts
           Version: 1.1 Final
          Platform: PC
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Controller
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


This happens when the input attribute of an action is set to another .do 
instead of a jsp page. The form has enctype set and after validation failure 
request becomes empty.

Here is how I solved this in RequestProcessor:
Note that getAllParametersForMultipartRequest() was copied from RequestUtils.
--------------------------------------------------------

protected boolean processValidate(HttpServletRequest request,
                                      HttpServletResponse response,
                                      ActionForm form,
                                      ActionMapping mapping)
        throws IOException, ServletException {

        if (form == null) {
            return (true);
        }

        // Was this request cancelled?
        if (request.getAttribute(Globals.CANCEL_KEY) != null) {
            if (log.isDebugEnabled()) {
                log.debug(" Cancelled transaction, skipping validation");
            }
            return (true);
        }

                // Special handling for multipart request
        if (form.getMultipartRequestHandler() != null) {
                
                // Handle repopulation of parameters.
                MultipartRequestWrapper wrapper = (MultipartRequestWrapper)
request;
            if(request.getAttribute(PARSED_MULTIPART_REQUEST) != null){
                                Map params = (Map)request.getAttribute
(PARSED_MULTIPART_REQUEST);
                                
                                // Populate fresh request.
                                Iterator iter = params.keySet().iterator();
                                while (iter.hasNext()) {
                                        String key = (String) iter.next();
                                        Object value = params.get(key);
                                        if(value instanceof String[]){
                                                String[] val = (String[]) value;
                                                if(val.length > 0){
                                                        System.out.println
("XXXXXXXX Setting parameter " + key + " to " + val[0]);
                                                        wrapper.setParameter
(key, val[0]);
                                                }
                                        }
                                }
            }
            else{
                
                // Retrive form values and put into properties.
                Map multipartParameters = getAllParametersForMultipartRequest(
                        request, form.getMultipartRequestHandler());
                        
                request.setAttribute(PARSED_MULTIPART_REQUEST, 
multipartParameters);
            }
        }
        
        return super.processValidate(request, response, form, mapping);
    }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to