Author: tchemit Date: 2009-05-03 21:10:18 +0000 (Sun, 03 May 2009) New Revision: 1375 Modified: jaxx/trunk/jaxx-runtime-validator/changelog.txt jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/field/CollectionFieldExpressionValidator.java Log: improve CollectionFieldExpressionValidator : can specify collection property name via collectionFieldName Modified: jaxx/trunk/jaxx-runtime-validator/changelog.txt =================================================================== --- jaxx/trunk/jaxx-runtime-validator/changelog.txt 2009-04-30 15:08:34 UTC (rev 1374) +++ jaxx/trunk/jaxx-runtime-validator/changelog.txt 2009-05-03 21:10:18 UTC (rev 1375) @@ -1,3 +1,6 @@ +1.5 + * 20090503 [chemit] - add a new property collectionFieldName on CollectionFieldExpression validator to be able to validate a collection but not for a collection field + 1.3 chemit 20090409 * 20090404 [chemit] - can now use a shared instance of ValueStack (in BeanValidatorUtil) * 20090401 [chemit] - introduce a extended fieldexpression validator where we can push extra parameters Modified: jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/field/CollectionFieldExpressionValidator.java =================================================================== --- jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/field/CollectionFieldExpressionValidator.java 2009-04-30 15:08:34 UTC (rev 1374) +++ jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/field/CollectionFieldExpressionValidator.java 2009-05-03 21:10:18 UTC (rev 1375) @@ -27,6 +27,17 @@ /** le mode de validation sur la liste */ protected Mode mode; /** + * pour indiquer la propriété qui contient la liste à valider. + * + * Si cette prorpiété n'est pas renseignée alors on utilise la + * {@link #getFieldName()} pour obtenir la collection. + * + * Cela permet d'effectuer une validation si une collection mais portant + * en fait sur un autre champs + * @since 1.5 + */ + protected String collectionFieldName; + /** * drapeau pour utiliser le contexte de parcours pour valider * l'expression, on dispose donc alors des variables previous, current, * index, size et empty dans l'expression. @@ -49,7 +60,7 @@ protected String expressionForLast; /** le context de parcours */ protected WalkerContext c; - private boolean useFirst, useLast; + private boolean useFirst, useLast; public Mode getMode() { return mode; @@ -59,6 +70,14 @@ this.mode = mode; } + public String getCollectionFieldName() { + return collectionFieldName; + } + + public void setCollectionFieldName(String collectionFieldName) { + this.collectionFieldName = collectionFieldName; + } + public boolean isUseSensitiveContext() { return useSensitiveContext; } @@ -114,7 +133,7 @@ stack.push(object); pop = true; } - + switch (mode) { case ALL: answer = validateAllEntries(col); @@ -276,7 +295,11 @@ * @throws ValidationException if any pb to retreave the collection */ protected Collection<?> getCollection(Object object) throws ValidationException { - String fieldName = getFieldName(); + String fieldName = getCollectionFieldName(); + if (fieldName == null || fieldName.trim().isEmpty()) { + // on travaille directement sur le fieldName + fieldName = getFieldName(); + } Object obj = null;