2010-04-30 82 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++; 
    } 
}