开发者

struts annotation issue

开发者 https://www.devze.com 2022-12-29 04:59 出处:网络
开发者_如何转开发My issue is that I have an annotation in Struts2 action class like private String[] origfilenofrom;

开发者_如何转开发My issue is that I have an annotation in Struts2 action class like

private String[] origfilenofrom;

@FieldExpressionValidator(fieldName="origfilenofrom",key="",message="File Length should be 12 for old file format and 15 for new file format",expression="checkorigFileFormat(origfilenofrom)")

Now my method is

public boolean checkorigFileFormat(String[] files )
 {   
  for(int counter=0;counter<files.length;counter++)
     {
   int n=files[counter].length();
   if(!(n==12 || n==15))
   {
    return false;
   }
     }
     return true;
 }

So for any string in that string [], which is returning false the value is being false. No matter 3 strings in that string [] are true if one is false then the annotation message is displayed for all.

I want the message not to display where the string is true.


I am trying to answer. I think you need to use validate method instead of annotation.

@Override
public void validate() {
 int count =0;
 for(String s : origfilenofrom)
   {
    if (!(s.length()==12 || s.length()==15)) {

    this.addActionError("File Length should be 12 for old file format and 15 for new file format for file no :"+ count);
      }
    count++;
   }
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号