struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kawczynski, David" <david_kawczyn...@merck.com>
Subject RE: How to validation/workflow with fileUpload?
Date Fri, 26 Sep 2008 18:04:50 GMT
I've used <s:file> with validation without errors.  
I've never provided a value attribute in the tag.
I don't know about struts, but I think the <input type="file"> tag ignores value attributes.
 
What happens if you remove the value attribute?

-----Original Message-----
From: Earle Flynn [mailto:eflynn00@yahoo.com] 
Sent: Friday, September 26, 2008 1:34 PM
To: Struts Users Mailing List
Subject: Re: How to validation/workflow with fileUpload?

Here is some addititional and new info;
-- resolved blank page issue by removing pjl compression filter from web.xml. will do gzip
at apache http or discuss with pjl project owner.
--on validation errors, action returns to input result as expected, which is good.
--although, if value property of s:file is not set then input page stops rendering right before
s:file tag, presumably there is an exception.
--explicitly declaring a 'value' property in s:file solved this issue.
 
ok, back to main issue, unable to upload a file after following showcase, the FileUploadInterceptor
sets a field error, 'Invalid field value for field "upload".' Does anyone know where this
field error is coming from? I can see the correct fileName and contentType in the action's
validate(), plus the actual file is put in /tmp with the long filename but not sure about
why the field error is set. conversion error? Here is my s:file tag;
 
<s:file name="upload" label="Picture" value="false"/>

thanks,
earle



----- Original Message ----
From: Earle Flynn <eflynn00@yahoo.com>
To: user@struts.apache.org
Sent: Thursday, September 25, 2008 3:42:01 PM
Subject: How to validation/workflow with fileUpload?

How is it possible to use validation/workflow interceptors in combination with fileUpload
interceptor?
 
For the config below, if I submit an html form that includes the file tag, struts returns
a blank white page instead of the intended success result. This occurs regardless of whether
form is filled out correctly or not. I would assume struts is looking for an input result
since there was a file upload error, assuming, though?
 
From log statements the validate() method is executed but the execute() method is not, despite
the form being filled out properly. The File object is even available in validate() and has
the correct info (fileName, contentType), I can even see the temp file since it’s not delete
since execute() does not run. What is the proper interceptor stack configuration for using
validation, workflow, and fileUpload?
 
I have tried setting each interceptor manually, in a number of different stack positions,
but it seems like file upload cancels out validation and workflow.
 
btw, if the same form is submitted without a file then the action behaves as expected.
 
The blank page problem occurs when the FileUploadInterceptor detects a file. Also, I have
tried to use SaveItem-validation.xml instead of manual validate() with the same results but
I also have a specific reason to use the manual validate().
 
Any suggestions to get the fileUpload interceptor to return either the success result or input
result instead of the blank page.
 -- jars in lib;
struts2-core 2.0.11.2
commons-fileupload 1.1.1
commons-io 1.0
 
-- struts-xml
 
<struts>
            <!-- Configuration for the default package. -->
            <package name="default" extends="struts-default">
            
        <action name="tokenPrepare!*" class="com.sandplains.view.action.SaveItem"
method="{1}">
            <result name="input">WEB-INF/jsp/post-item.jsp</result>
        </action>
 
        <action name="saveitem" class="com.sandplains.view.action.SaveItem">
                <interceptor-ref name="token"/>
            <interceptor-ref name="exception"/>
            <interceptor-ref name="alias"/>
            <interceptor-ref name="servletConfig"/>
            <interceptor-ref name="prepare"/>
            <interceptor-ref name="i18n"/>
            <interceptor-ref name="chain"/>
            <interceptor-ref name="debugging"/>
            <interceptor-ref name="profiling"/>
            <interceptor-ref name="scopedModelDriven"/>
            <interceptor-ref name="modelDriven"/>
            <interceptor-ref name="fileUpload"/>
            <interceptor-ref name="checkbox"/>
            <interceptor-ref name="staticParams"/>
            <interceptor-ref name="params">
                        <param name="excludeParams">dojo\..*</param>
            </interceptor-ref>
            <interceptor-ref name="conversionError"/>
            <interceptor-ref name="validation">
                <param name="excludeMethods">input,back,cancel,browse</param>
            </interceptor-ref>
            <interceptor-ref name="workflow">
                <param name="excludeMethods">input,back,cancel,browse</param>
            </interceptor-ref>
 
            <result name="input">WEB-INF/jsp/post-item.jsp</result>
            <result name="invalid.token">/error/dbl-click-post-item.jsp</result>
            <result>WEB-INF/jsp/results-save-item.jsp</result>
            <result name="failure">/error/error.jsp</result>
        </action>
 
            </package>
</struts>
 
-- struts.properties
 
struts.multipart.parser=jakarta
struts.multipart.saveDir=c:/tmp
struts.multipart.maxSize=1000000
 
-- jsp
<s:form name="savefrm" action="saveitem.does" method="post" enctype="multipart/form-data">
            <s:token/>
            <s:textarea label="Desc" name="description" cols="35" rows="4" required="true"/>
            <s:file name="upload" label="Picture"/>
            <s:submit name="submit1" align="left"/>
</s:form>
 
action
 
public class SaveItem extends ActionSupport {
            private static final long serialVersionUID = 1L;
            static Logger log = Logger.getLogger(SaveItem.class);
 
            private String description;
 
            private File file;
            private String contentType;
            private String filename;
 
            public String execute() throws Exception {
 
                        if (AppConstants.DEBUG) {
                                    log.info("description:
" + description);
                                    log.info("contentType:
" + contentType);
                                    log.info("filename:
" + filename);
                        }
                        
                        // do stuff...
 
 
                        return SUCCESS;
            }
 
            public void validate() {
                        log.info("filename: " + filename);
                        log.info("contentType: " + contentType);
                        
                        //
                        // Validate fields.
                        //
                        if (description != null && description.trim().length()
> 0) {
                                    if (description.length()
> 5000) {
                                               
addFieldError("description",
                                                                       
"Description must not be more than 5000 characters, including whitespace.");
                                    }
                        } else {
                                    addFieldError("description",
"Description is a required field.");
                        }
 
            }
 
            public void setUpload(File file) {
                        this.file = file;
            }
 
            public void setUploadContentType(String contentType) {
                        this.contentType = contentType;
            }
 
            public void setUploadFileName(String filename) {
                        this.filename = filename;
            }
}


      
Notice:  This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station,
New Jersey, USA 08889), and/or its affiliates (which may be known
outside the United States as Merck Frosst, Merck Sharp & Dohme or
MSD and in Japan, as Banyu - direct contact information for affiliates is
available at http://www.merck.com/contact/contacts.html) that may be
confidential, proprietary copyrighted and/or legally privileged. It is
intended solely for the use of the individual or entity named on this
message. If you are not the intended recipient, and have received this
message in error, please notify us immediately by reply e-mail and
then delete it from your system.
Mime
View raw message