[ 
https://issues.apache.org/struts/browse/WW-2112?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42457
 ] 

Kjell Martin Rud commented on WW-2112:
--------------------------------------

I do not believe this issue has been resolved and that it should be reopened. 
First of all, it does not have to be only AppendingValidatorContext that 
recursivly appends field names. getFullFieldName(..) is defined in 
ValidatorContext interface and should therefor be used by 
AppendingValidatorContext regardless of the implementing class. This would 
result in AppendingValidatorContext having the following implementation of 
getFullFieldName(...):

                public String getFullFieldName(String fieldName) {
                        return parent.getFullFieldName(field + "." + fieldName);
                }

provided, as with the prior solution proposal, that "parent" is an instance 
variable of AppendingValidatorContext.

But, AppendingValidatorContext also converts any action errors added to field 
errors giving the full parent field name. This field name was not changed in 
the prior solution and will therefor give a wrong property path for the field 
error. A possible solution is to change the implementation of 
addActionError(...) to the following:

                public void addActionError(String anErrorMessage) {
                        super.addFieldError(parent.getFullFieldName(field), 
message + anErrorMessage);
                }


> @ConversionErrorFieldValidator and Collections not working
> ----------------------------------------------------------
>
>                 Key: WW-2112
>                 URL: https://issues.apache.org/struts/browse/WW-2112
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Interceptors
>    Affects Versions: 2.0.9
>         Environment: WebSphere 6.1.0.9 on Windows
>            Reporter: Martin Petzsch
>            Assignee: Don Brown
>             Fix For: 2.0.11
>
>
> @ConversionErrorFieldValidator does not work with property inside bean in 
> collection.  Validation in the same location does work.
> A data bean which a jsp uses through an action.  This bean contains a date 
> field. I annotate the set method with:
>       @ConversionErrorFieldValidator(message="aDate: Conversion Error")
>       @RequiredFieldValidator(message="aDate: Required Field")
>       public void setADate(Date date) {
>               aDate = date;
>       }
> This works fine and I get the messages about type conversion and validation 
> failure in the expected order depending on my input.
> The same data bean also contains a List of another data bean and the 
> associated methods:
>       private List<InnerBean> innerList;
>       @VisitorFieldValidator(message="Inner Message:",appendPrefix=true)
>       public List<InnerBean> getInnerList() {
>               if (innerList == null) {
>                       innerList = new ArrayList<InnerBean>();
>                       innerList.add(new InnerBean());
>               }
>               return innerList;
>       }
>       public void setInnerList(List<InnerBean> innerList) {
>               this.innerList = innerList;
>       }
> My inner bean is as follows:
>       private Date innerProp;
>       public Date getInnerProp(){
>               return innerProp;
>       }
>       
>       @ConversionErrorFieldValidator(message="innerProp: Conversion Error")
>       @RequiredFieldValidator(message="innerProp: Required Field")
>       public void setInnerProp(Date str){
>               innerProp = str;
>       }
> The required field validator works as expected.  I do not however get any 
> result EVER back from the ConversionErrorFieldValidator on the inner bean.  
> If I enter an incorrect value it simply does not get set.
> Source Code Follows
> ===============================================
> import java.util.ArrayList;
> import java.util.Date;
> import java.util.List;
> import 
> com.opensymphony.xwork2.validator.annotations.ConversionErrorFieldValidator;
> import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator;
> import com.opensymphony.xwork2.validator.annotations.VisitorFieldValidator;
> public class MyDataBean {
>       private Date aDate;
>       private List<InnerBean> innerList;      
>       
>       public MyDataBean() {
>       }
>       @VisitorFieldValidator(message="Inner Message",appendPrefix=false)
>       public List<InnerBean> getInnerList() {
>               if (innerList == null) {
>                       innerList = new ArrayList<InnerBean>();
>                       innerList.add(new InnerBean());
>               }
>               return innerList;
>       }
>       public void setInnerList(List<InnerBean> innerList) {
>               this.innerList = innerList;
>       }
>       public Date getADate() {
>               return aDate;
>       }
>       // this works fine
>       @ConversionErrorFieldValidator(message="aDate: Conversion Error")
>       @RequiredFieldValidator(message="aDate: Required Field")
>       public void setADate(Date date) {
>               aDate = date;
>       }
> }
> --------
> /**
>  * 
>  */
> import java.util.Date;
> import 
> com.opensymphony.xwork2.validator.annotations.ConversionErrorFieldValidator;
> import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator;
> /**
>  * @author MPETZSCH
>  *
>  */
> public class InnerBean {
>       private Date innerProp;
>       
>       public Date getInnerProp(){
>               return innerProp;
>       }
>       
>       // this does not work
>       @ConversionErrorFieldValidator(message="innerProp: Conversion Error")
>       @RequiredFieldValidator(message="innerProp: Required Field")
>       public void setInnerProp(Date str){
>               innerProp = str;
>       }
> }

-- 
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