Results 1 to 8 of 8

Thread: Valang and arrays

  1. #1
    Join Date
    Oct 2005
    Posts
    2

    Default Valang and arrays

    Can you please tell me if it is possible, and if so, how to do validation of an array with Valang?

    from the bean:
    {setOfXTableArray[0].fullAmount : ? < 5 : 'fullAmount too big' }

    This works fine for the first element but I want to test all the elements and the number of elements is not fixed.

    ps: to edit the table I am using the spring bind for a collection http://opensource2.atlassian.com/pro.../browse/SPR-52

    thanks,
    Bert.

  2. #2
    Join Date
    May 2005
    Posts
    23

    Default

    i need to do the same thing (only against a collection and not an array).

    i was thinking about wrapping the valang validator instance in another validator instance that knows how to loop over the the collection, but i still need to figure out how to correctly reflect which input row is incorrect.

    if i get it working, i'll post back my solution.
    -jae

  3. #3
    Join Date
    Sep 2004
    Location
    Boston, US
    Posts
    130

    Default validation rules at collection level

    I too need this feature. We have several editable tables where we need to enforce field validation across all rows. The lack of support for field validation operations at the collection level is the only thing that's keeping me from using Valang. I hope this feature is added soon as I cant wait to switch to using Valang.

    In addition to single field level validation rules across a collection, it would be very useful if one could specify uniqueness constraints on one or more bean properties. For example in an editable table displaying items, the item name can be edited by the user however no two items in the table should be the same.

    Thanks,
    Sanjiv

  4. #4
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Guys, why don't you ask your questions on the Spring Modules user mailing list?
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  5. #5
    Join Date
    Mar 2007
    Posts
    7

    Default validate custom list

    I'm also interested in this, I have for example a valiable list of Contacts
    the validation works well for 1 contacts, but I must apply the same validation for the others.

    valang:

    Code:
    { contact[0].name : ? is not blank : 'es required' : 'contactNameEmpty' }
    form:
    Code:
    <@spring.bind "contacts.contact[0].name" />
    name: <input type="text" name="${spring.status.expression}" value="${spring.status.value?default("")}"><@spring.showErrors ", " "error" /><br>
    
    ...
    <@spring.bind "contacts.contact[1].name" />
    name: <input type="text" name="${spring.status.expression}" value="${spring.status.value?default("")}"><@spring.showErrors ", " "error" /><br>
    databinder:
    Code:
    public class ContactsInputBinder {
    
    	private List contacts= LazyList.decorate(new ArrayList(), FactoryUtils.instantiateFactory(Contact.class));
    	
    	public IngresoClienteBinder()
    	{
    	}
    	
    	public List getContacts() {
    		return contacts;
    	}
    
    	public void setContacts(List contacts) {
    		this.contacts= contacts;
    	}
    	
    	
    }

    I don't know beforehand how many contacs there are, so how can I write the validator?

  6. #6
    Join Date
    Aug 2008
    Posts
    5

    Default

    Resurrecting this question - is there a way to apply a validation rule to all items in a collection and/or map?

  7. #7
    Join Date
    Jul 2009
    Posts
    3

    Default i am facing the same problem

    after 4 years of the start of this thread, it seems this is mission impossible.

  8. #8

    Default gaga

    I found it's possible, I rewrite the ValangValidator class, and it works perfectly for first level,which means xxx[0].property, but not implement the xxx[i].yy[j].property

Posting Permissions

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