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

これは、この FinancialTransactionType 内の私のバリデータ コードです。オブジェクトの FinancialTransactionType としてモデル化されています。

public class MiniStatementViewModel {


private boolean isMiniStatement;

private Date fromDate;

private Date toDate;

private String accountCode;

private FinancialTransactionType financialTransactionType;

したがって、JSPでエラーメッセージを表示すると、次のようなエラーメッセージが表示されます

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
4

1 に答える 1

0

このエラーはNONE、フォームから文字列値を取得していることを意味し、その値をフィールドに合わせるためにfinancialTransactionTypeFinancialTransactionType.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");
    }
于 2013-09-03T07:04:55.010 に答える