modular-j2ee.zip
jln-core
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
org.eclipse.pde.core.prefs
build.properties
META-INF
config
jdbc.properties
MANIFEST.MF
spring
jln-entities
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
org.eclipse.pde.core.prefs
bin
com
cp
adrabi
jln
model
Todo.class
build.properties
META-INF
MANIFEST.MF
src
com
cp
adrabi
jln
model
jln-log-config
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
org.eclipse.pde.core.prefs
build.properties
log4j.properties
META-INF
MANIFEST.MF
jln-persistence-1.0.0
.project
.settings
org.eclipse.pde.core.prefs
build.properties
META-INF
MANIFEST.MF
persistence
1.0.0
jln-todo-component
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
org.eclipse.pde.core.prefs
.springBeans
bin
com
cp
adrabi
jln
todo
services
impl
TodoServiceImpl.class
TodoService.class
build.properties
META-INF
MANIFEST.MF
spring
src
com
cp
adrabi
jln
todo
services
impl
jln-todo-component-test
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
resources
log4j.properties
src
com
cp
adrabi
jln
todo
tests
integration
utils
jln-validation-config
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
org.eclipse.pde.core.prefs
.springBeans
bin
javax
validation
ValidatorFactoryProxy.class
build.properties
META-INF
MANIFEST.MF
services
javax.validation.spi.ValidationProvider
spring
src
javax
validation
jln-web-core
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
org.eclipse.pde.core.prefs
.springBeans
bin
com
cp
adrabi
web
controllers
BasicComposer.class
build.properties
jln
404.jsp
index.zul
login.zul
META-INF
MANIFEST.MF
src
com
cp
adrabi
web
controllers
WEB-INF
components
gentlepage.zul
spring
jln-web-todo
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
org.eclipse.pde.core.prefs
.springBeans
bin
com
cp
adrabi
jln
web
todo
components
TodoRowModel$1.class
TodoRowModel$2.class
TodoRowModel.class
controllers
ControllerBaseTodo.class
ControllerListTodo.class
ControllerNewTodo.class
ControllerRemoveTodo.class
ControllerUpdateTodo.class
build.properties
jln
admin
todo
list.zul
new.zul
remove.zul
update.zul
META-INF
MANIFEST.MF
src
com
cp
adrabi
jln
web
todo
components
controllers
WEB-INF
spring
|
package com.cp.adrabi.web.controllers;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.ValidatorFactory;
import javax.validation.groups.Default;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zk.ui.WrongValuesException;
import org.zkoss.zk.ui.util.GenericForwardComposer;
/**
* Base of all controllers
*
* @author ADRABI Abderrahim (z3vil)
*
*/
public class BasicComposer extends GenericForwardComposer
{
/**
*
*/
private static final long serialVersionUID = 1L;
private ValidatorFactory validatorFatory;
private List<WrongValueException> wrongValues = new ArrayList<WrongValueException>();
/**
* Validation JSR 303
*
* @param <T>: anonymous type
* @param comp: component
* @param beanClass: bean class to validate
* @param propertyName: property name to check and validate
* @param value: value in question
*/
protected <T> void validateValue(final Component comp,final Class<T> beanClass, final String propertyName, final Object value)
{
final Set<ConstraintViolation<T>> violations = this.validatorFatory.getValidator().validateValue(beanClass,propertyName, value, Default.class);
// only one violation
if( violations.size() == 1 )
{
this.wrongValues.add(new WrongValueException(comp, violations.iterator().next().getMessage()));
}
// many violations
else if( violations.size() > 1 )
{
StringBuilder builder = new StringBuilder();
for(ConstraintViolation<T> cv : violations)
{
builder.append(cv.getMessage() + "\n");
}
builder.deleteCharAt(builder.length() - 1);
this.wrongValues.add(new WrongValueException(comp, builder.toString()));
}
}
/**
* Fire validation for throwing exceptions
*
* @throws WrongValuesException
*/
protected void fireValidation() throws WrongValuesException
{
if(!this.wrongValues.isEmpty())
{
WrongValueException[] wrongs = this.wrongValues.toArray(new WrongValueException[]{});
this.wrongValues.clear();
throw new WrongValuesException(wrongs);
}
}
public ValidatorFactory getValidatorFatory()
{
return validatorFatory;
}
public void setValidatorFatory(ValidatorFactory validatorFatory)
{
this.validatorFatory = validatorFatory;
}
}
|
By viewing downloads associated with this article you agree to the Terms of use and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.