[ 
https://issues.apache.org/struts/browse/WW-1257?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Don Brown updated WW-1257:
--------------------------

    Fix Version/s:     (was: 2.1.x)
                   2.2.x

> Added validation support to the ww:file tag
> -------------------------------------------
>
>                 Key: WW-1257
>                 URL: https://issues.apache.org/struts/browse/WW-1257
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugin - Tags
>    Affects Versions: WW 2.2.1
>         Environment: n/a
>            Reporter: Jeff Cunningham
>            Assignee: Rainer Hermanns
>            Priority: Minor
>             Fix For: 2.2.x
>
>
> Hi...i added some error logic to my ww:file tag to support validation for the 
> file tag. This enables users to make the filename required, or to make the 
> filetype (by checking the suffix) match only certain types. For my case, I 
> was able to make the filename required, and ensure the filename ended with 
> .jpg
> I'm sure the code I added to the webwork tag can be improved..right now it 
> takes advantage of the fact that webwork creates a String by appending 
> FileName to the name of the File object int the action...knowing that 
> simplified the code needed in the ww:file tag, and made it very easy to add 
> validation logic that follows the normal webwork rules.
> Here is my modified ww:file component:
> <#assign filename = parameters.name + "FileName"/>
> <#assign hasFieldErrors = fieldErrors?exists && fieldErrors[filename]?exists/>
> <#if hasFieldErrors>
> <#list fieldErrors[filename] as error>
>     <label class="feedback"><#rt/>
>              ${error?html}
>     </label><#t/>
>     <br />
> </#list>
> <#t/>
> </#if>
> <input type="file"<#rt/>
>  name="${parameters.name?default("")?html}"<#rt/>
> <#if parameters.get("size")?exists>
>  size="${parameters.get("size")?html}"<#rt/>
> </#if>
> <#if parameters.nameValue?exists>
>  value="<@ww.property value="parameters.nameValue"/>"<#rt/>
> </#if>
> <#if parameters.disabled?default(false)>
>  disabled="disabled"<#rt/>
> </#if>
> <#if parameters.accept?exists>
>  accept="${parameters.accept?html}"<#rt/>
> </#if>
> <#if parameters.tabindex?exists>
>  tabindex="${parameters.tabindex?html}"<#rt/>
> </#if>
> <#if parameters.id?exists>
>  id="${parameters.id?html}"<#rt/>
> </#if>
> <#if parameters.cssClass?exists>
>  class="${parameters.cssClass?html}"<#rt/>
> </#if>
> <#if parameters.cssStyle?exists>
>  style="${parameters.cssStyle?html}"<#rt/>
> </#if>
> <#include "/${parameters.templateDir}/simple/scripting-events.ftl" />
> />
> And here is an example snippet from a validation xml file. Note that the keys 
> are stored in the property file for the action, and not included here. I 
> obviously had a File object named file in my Action class...
>     <field name="fileFileName">
>         <field-validator type="requiredstring">
>             <message key="form.error.fileFileName.required"/>
>         </field-validator>
>         <field-validator type="fieldexpression">
>               <param name="expression">fileFileName.endsWith(".jpg")</param>
>             <message key="form.error.fileFileName.fieldexpression"/>
>         </field-validator>
>     </field>
> Anyway..i thought adding the error logic to the file tag was fairly trivial, 
> and would enable nice and simple validations like the above, with minimal 
> work for the developer.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to