Results 1 to 4 of 4

Thread: Dynamic Validation

Hybrid View

  1. #1
    Join Date
    Aug 2005
    Posts
    13

    Default Dynamic Validation

    hey guys how can i validate array of data dynamically(the array is created dynamically by

    javascript) knowing that i get error every time saying that it is not a binded object and it is a

    string (the object i am trying to validate it)so how can i overcome this ?

    thnaks alot for your time

  2. #2
    Join Date
    Apr 2005
    Location
    Finland
    Posts
    314

    Default

    Quote Originally Posted by 4s
    hey guys how can i validate array of data dynamically(the array is created dynamically by javascript) knowing that i get error every time saying that it is not a binded object and it is a string (the object i am trying to validate it)so how can i overcome this ?

    thnaks alot for your time
    Hi,

    some detailed information & code would help to solve the problem you're having. You can call the validator e.g. in the 'SimpleFormController' by implementing some appropriate method.
    And as far as I know, you can manually bind the data aswell in the controller.

    I hope this helps... if not, post some detailed data

  3. #3
    Join Date
    Aug 2004
    Location
    Hawaii, US
    Posts
    225

    Default

    Unfortunately, Spring won't automatically populate collections when it is trying to access some element inside that collection. If it's null, then it's null.

    However, there are a couple of things you can do.

    The first would be to populate the collection with the correct amount of objects that you expect. This might mean a two step process:

    1) Add new object
    2) Edit object

    The second thing you can try is use LazyList from commons-collections.

    http://jakarta.apache.org/commons/co.../LazyList.html

    If you try to access an element in the list that doesn't yet exist, then it will create on automatically for you.

    Seth

  4. #4
    Join Date
    Aug 2005
    Posts
    13

    Default

    thanks alot for replying : well as for detailed info
    the error i get is : java.lang.ClassCastException: java.lang.String

    and the validation code that i used to validate the dynamic list is like this :


    private void validateEquality(PaymentDocument document,
    Errors errors) {
    Long amount=document,.getAmount();
    Long Sum=new Long(0);

    //where Financialtransactiondetails is the list that contains the dynamic //data

    Iterator itr=document,.getFinancialtransactiondetails().ite rator();


    while(itr.hasNext())
    {
    Object currenct=itr.next();
    Long cashAmount = new Long(((FinancialTransactionDetails)currenct).getAm ount());
    log.debug(">>>>>>>>>>>>>>>>>>> cashAmount "+cashAmount);
    Sum+=cashAmount;
    }
    //if the sum of all the money = the amount that the user entered then //every thing is good else i will raise an error

    if(!Sum.equals(amount))
    errors.rejectValue("amount","Error In Amount","Total Amount Must Be Equal To Details Amount");

    }

    --------------------------------------------------END OF VALIDATION-----------------------------------------------

    *when i enter a wrong amount then i will be prompeted to enter the correct amount(that is right) and when i enter the correct amount (just to correct the wrong amount i entred before) i get the CLASS CAST EXCEPTION , if i entred it correct from the 1st time everything will work just fine......well got any idea

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •