2013-09-03 5 views
0
@Override 
public void validate(Object target, Errors errors) { 

    Date today = new Date(); 
    MiniStatementViewModel miniStatementViewModel=(MiniStatementViewModel) target; 


    else if(miniStatementViewModel.getFinancialTransactionType()==null) 
    { 
    errors.rejectValue("financialTransactionType","financialTransactionTypeNull"); 
    } 

이 내가 JSP에 오류 MSG에 오류가 있습니다 보여줄 때이 financialTransactionType 내 검증 코드가,유효성 검사 오류

public class MiniStatementViewModel { 


private boolean isMiniStatement; 

private Date fromDate; 

private Date toDate; 

private String accountCode; 

private FinancialTransactionType financialTransactionType; 

그래서 객체의 FinancialTransactionType로 모델입니다 MSG는

Failed to convert property value of type java.lang.String to required type mkcl.os.apps.solar.account.model.FinancialTransactionType for property financialTransactionType; 
nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type mkcl.os.apps.solar.account.model.FinancialTransactionType for value NONE; 
nested exception is java.lang.IllegalArgumentException: No enum const class mkcl.os.apps.solar.account.model.FinancialTransactionType.NONE 

답변

0

처럼 그 오류는이 Financ을 수행 financialTransactionType 필드에 그 값을 맞추기 위해, 양식에서 문자열 값 NONE을 받고, 그리고 의미 ialTransactionType.valueOf ("NONE")이며 존재하지 않기 때문에 오류를 반환합니다.

public class MiniStatementViewModel { 


private boolean isMiniStatement; 

private Date fromDate; 

private Date toDate; 

private String accountCode; 

private String financialTransactionType; 

및 검증 :

은 당신의 클래스를 변경

@Override 
public void validate(Object target, Errors errors) { 

    Date today = new Date(); 
    MiniStatementViewModel miniStatementViewModel=(MiniStatementViewModel) target; 


    else if(FinancialTransactionType.valueOf(miniStatementViewModel.getFinancialTransactionType())==null) 
    { 
    errors.rejectValue("financialTransactionType","financialTransactionTypeNull"); 
    }