Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » Java » General » Downloads
 
Add your own
alternative version

Modular J2EE, Using Spring DM, Zk and EclipseLink

, 21 Apr 2011
This article describes how to create a basic modular Java Enterprise Application, by using these Open Source frameworks
modular-j2ee.zip
jln-core
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
org.eclipse.pde.core.prefs
META-INF
MANIFEST.MF
config
jdbc.properties
spring
build.properties
jln-entities
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
org.eclipse.pde.core.prefs
META-INF
MANIFEST.MF
bin
com
cp
adrabi
jln
model
Todo.class
build.properties
src
com
cp
adrabi
jln
model
jln-log-config
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
org.eclipse.pde.core.prefs
META-INF
MANIFEST.MF
build.properties
log4j.properties
jln-persistence-1.0.0
.project
.settings
org.eclipse.pde.core.prefs
META-INF
MANIFEST.MF
persistence
1.0.0
build.properties
jln-todo-component
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
org.eclipse.pde.core.prefs
.springBeans
META-INF
MANIFEST.MF
spring
bin
com
cp
adrabi
jln
todo
services
TodoService.class
impl
TodoServiceImpl.class
build.properties
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
META-INF
MANIFEST.MF
services
javax.validation.spi.ValidationProvider
spring
bin
javax
validation
ValidatorFactoryProxy.class
build.properties
src
javax
validation
jln-web-core
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
org.eclipse.pde.core.prefs
.springBeans
META-INF
MANIFEST.MF
WEB-INF
components
gentlepage.zul
spring
bin
com
cp
adrabi
web
controllers
BasicComposer.class
build.properties
jln
404.jsp
index.zul
login.zul
src
com
cp
adrabi
web
controllers
jln-web-todo
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
org.eclipse.pde.core.prefs
.springBeans
META-INF
MANIFEST.MF
WEB-INF
spring
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
src
com
cp
adrabi
jln
web
todo
components
controllers
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 Service 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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Adrabi Abderrahim
Technical Lead
Morocco Morocco
Adrabi!, Just another Ghost in the Shell =)

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 21 Apr 2011
Article Copyright 2011 by Adrabi Abderrahim
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid