我的问题是我在Struts2动作类中有一个注释,如
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)")
现在我的方法是
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;
}
因此,对于该字符串[]中的任何字符串,返回false,该值为false。 无论该string []中的3个字符串是否为真,如果一个为假,则显示所有的注释消息。
我希望消息不显示字符串为true的位置。
答案 0 :(得分:0)
我想回答。 我认为您需要使用验证方法而不是注释。
@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++;
}
}