hashmap validation in spring -
my hashmap :
hashmap h = new hashmap(); hashmap h2 = new hashmap(); list<hashmap> lh = new arraylist<hashmap>(); hashmap ch; lh = new arraylist<hashmap>(); ch = new hashmap(); ch.put("op", "=="); ch.put("value", "20dd1"); lh.add(ch); h2.put("location", lh); lh = new arraylist<hashmap>(); ch = new hashmap(); ch.put("op", ">="); ch.put("value", "1239"); lh.add(ch); ch = new hashmap(); ch.put("op", "<="); ch.put("value", "1234"); lh.add(ch); h2.put("invno", lh); lh = new arraylist<hashmap>(); ch = new hashmap(); ch.put("op", ">="); ch.put("value", "1239"); lh.add(ch); ch = new hashmap(); ch.put("op", "<="); ch.put("value", "1234"); lh.add(ch); h2.put("issdate", lh); h.put("invoice", h2);
i want validate hashmap (search jsp) 2 condition:
1) type check (int/double/float etc) 2) range check like entry invoice no. from, invoice no. to
my validate function is: (working)
1) iterator iterator = typech.entryset().iterator(); while (iterator.hasnext()) { map.entry mapentry = (map.entry) iterator.next(); string key = (string) mapentry.getkey(); if (key.equals(field)) { string type = (string) mapentry.getvalue(); if (type.equals("intvalidator")) { try { sent.put(field, "ok: " + integer.parseint(value)); } catch (exception e) { sent.put(field, "must 0-9"); } } else if (type.equals("decimalvalidator")) { try { sent.put(field, "ok: " + double.parsedouble(value)); } catch (exception e) { sent.put(field, "must double"); } } } 2) int = integer.parseint(val.get(1)); int = integer.parseint(val.get(2)); if (from > to) { sent.put(field, "from must less to"); } else { sent.put(field, "ok"); }
i want create these type of validations in spring.
how can these? pls help!!
you can implement hashmap in spring application context , share across ioc using following util:map
. that, first include xmlns:util
in schema (in spring configuration file).
xmlns:util="http://www.springframework.org/schema/util"
then define map:
<util:map id="typech" key-type="java.lang.string" value-type="java.lang.string" map-class="java.util.hashmap"> </util:map>
then in java source code:
@resource map<string, string> typech;
populate map once , send class having validation logic.
Comments
Post a Comment