Note that there are some explanatory texts on larger screens.

plurals
  1. POstruts2 can't upload file. Invalid field value
    primarykey
    data
    text
    <p>When I try upload file in struts2 I get in my view a validation error: <strong>Invalid field value for field "upload".</strong> And in JBoss console I get: </p> <pre><code>10:37:56,140 WARN [OgnlValueStack] Error setting expression 'upload' with value '[Ljava.lang.String;@17c7b19' ognl.MethodFailedException: Method "setUpload" failed for object bm.action.content.SaveNewBannerAction@13ebb53 [java.lang.NoSuchMethodException: bm.action.content.SaveNewBannerAction.setUpload([Ljava.lang.String;)] at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1289) at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:1478) at ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:85) at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:162) ... ... Caused by: java.lang.NoSuchMethodException: bm.action.content.SaveNewBannerAction.setUpload([Ljava.lang.String;) at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1230) /-- Encapsulated exception ------------\ java.lang.NoSuchMethodException: bm.action.content.SaveNewBannerAction.setUpload([Ljava.lang.String;) at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1230) at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:1478) at ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:85) at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:162) </code></pre> <p>My jsp:</p> <pre><code>&lt;div class="v4DDfiltering"&gt; &lt;s:fielderror/&gt; &lt;s:form id="saveNewBannerForm" name="saveNewBannerForm" action="SaveNewBannerAction" theme="simple" method="POST" enctype="multipart/form-data"&gt; ... &lt;div class="OneFilteringRow"&gt; &lt;s:label for="upload" value="Plik:*" /&gt; &lt;s:file id="upload" name="upload"/&gt; &lt;/div&gt; ... &lt;div class="OneFilteringRow"&gt; &lt;s:url id="saveNewBannerUrl" action="SaveNewBannerAction" /&gt; &lt;sj:a href="%{saveNewBannerUrl}" targets="messagesDiv" formIds="saveNewBannerForm"&gt; Save &lt;/sj:a&gt; &lt;/div&gt; &lt;/s:form&gt; &lt;/div&gt; </code></pre> <p>My action class SaveNewBannerAction.java</p> <pre><code>public class SaveNewBannerAction extends BaseAction { private static final long serialVersionUID = 1L; private static final Log LOG = LogFactory.getLog(SaveNewBannerAction.class); private boolean validate = true; private File upload;// The actual file private String uploadContentType; // The content type of the file private String uploadFileName; // The uploaded file name private String fileCaption;// The caption of the file entered by user ... public File getUpload() { return upload; } public void setUpload(File upload) { this.upload = upload; } public String getUploadContentType() { return uploadContentType; } public void setUploadContentType(String uploadContentType) { this.uploadContentType = uploadContentType; } public String getUploadFileName() { return uploadFileName; } public void setUploadFileName(String uploadFileName) { this.uploadFileName = uploadFileName; } public String getFileCaption() { return fileCaption; } public void setFileCaption(String fileCaption) { this.fileCaption = fileCaption; } @Override public void validate() { LOG.info("Enter: validate()"); LOG.info("VALIDATE FIELDS"); ... if(upload == null) { addFieldError("upload", "Proszę uzupełnić pole: plik."); validate = false; } else { if(!uploadContentType.contains("image")) { addFieldError("upload", "Wprowadzono niepoprawny format pliku. Plik musi być obrazkiem."); validate = false; } } LOG.info("Exit: validate()"); } </code></pre> <p>I will be grateful for your help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload