Struts 2/ Foundation 5 - ModelDriven Class And File Upload
Solution 1:
Your problem is that you are defining a wrong Interceptor Stack for your Action.
The default one is defaultStack, while the one you used after the FileUpload Interceptor is the basicStack.
As you can see in the official documentation, the basicStack has no ModelDriven support. Change your action configuration from :
<interceptor-ref name="fileUpload">
<param name="allowedTypes">image/jpeg,image/png,image/gif</param>
<param name="maximumSize">4194304</param>
</interceptor-ref>
<interceptor-ref name="basicStack"></interceptor-ref>
to :
<interceptor-ref name="fileUpload">
<param name="allowedTypes">image/jpeg,image/png,image/gif</param>
<param name="maximumSize">4194304</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
or even better (to avoid using the FileUpload Interceptor twice) to :
<interceptor-ref name="defaultStack">
<param name="fileUpload.allowedTypes">image/jpeg,image/png,image/gif</param>
<param name="fileUpload.maximumSize">4194304</param>
</interceptor-ref>
Also consider using Struts2 tags to generate the HTML (use simple theme for the maximum control of the generated HTML, or XHTML, the default one, for the maximum assistance in HTML generation).
In many of the tags (the ones with Dynamic Attributes Allowed: true in the documentation), like <s:textfield/>, <s:textarea/>, <s:file/> and so on, you can define your own attributes, like the HTML5 pattern , for example.
The HTML will be cleaner and you will code it faster.
Post a Comment for "Struts 2/ Foundation 5 - ModelDriven Class And File Upload"