2010-04-30 26 views
0

我的问题是,我在Struts2的action类像支柱标注问题

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

所以对于该字符串[]任意字符串,它返回错误的价值是假的。 无论该字符串[]中的3个字符串是否为true,如果其中一个为false,则会为所有字符显示注释消息。

我希望消息不要显示字符串为真的地方。

+0

so none can answer this ...这是Struts 2设计框架的一个问题.. ....任何评论 – Gourav 2010-05-01 06:26:57

回答

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++; 
    } 
}