struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Gainty <mgai...@hotmail.com>
Subject RE: How to validation/workflow with fileUpload?
Date Fri, 26 Sep 2008 23:46:48 GMT

and if you change the action name 
<action name="saveitem" class="com.sandplains.view.action.SaveItem">
to same name references in the action attribute in s:form
<s:form action="saveitem"?
Martin 
______________________________________________ 
Disclaimer and confidentiality note 
Everything in this e-mail and any attachments relates to the official business of Sender.
This transmission is of a confidential nature and Sender does not endorse distribution to
any party other than intended recipient. Sender does not necessarily endorse content contained
within this transmission. 


> Date: Fri, 26 Sep 2008 14:40:36 -0700
> From: eflynn00@yahoo.com
> Subject: Re: How to validation/workflow with fileUpload?
> To: user@struts.apache.org
> 
> Laurie,
> I added the getters and received the same result for the upload s:file field, 'Invalid
field value for field "upload".' The message seems to be coming from the FileUploadInterceptor.
> 
> Earle
> 
> 
> 
> ----- Original Message ----
> From: Laurie Harper <laurie@holoweb.net>
> To: user@struts.apache.org
> Sent: Friday, September 26, 2008 3:53:42 PM
> Subject: Re: How to validation/workflow with fileUpload?
> 
> Glancing through your action code, you have setters but no getters. 
> Without getters, there is no way for Struts' validation code to access 
> the values to validate them, or for the form tags in the JSP to access 
> them. That might be the problem...
> 
> L.
> 
> Earle Flynn wrote:
> > 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;
> >             }
> > }
> > 
> > 
> >      
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
>       

_________________________________________________________________
Stay up to date on your PC, the Web, and your mobile phone with Windows Live.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093185mrt/direct/01/
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message