[jboss-user] [JBoss Seam] - Re: validation / exception handling patterns with EntityHome
pete.muir@jboss.org
do-not-reply at jboss.com
Mon Jul 2 13:14:41 EDT 2007
You could write a validator for this
@Name("uniqueValidator")
| @Validator
| @Transactional
| public class UniqueValidator {
|
| @In EntityManager entityManager;
|
| public void validate(FacesContext facesContext, UIComponent component, Object value)
| throws ValidatorException {
| Foo foo = (Foo) value;
| Foo foo1 = entityManager.createQuery("select f from Foo f where f.uniqueProperty = :uniqueProperty").setParameter("uniqueProperty, foo.getUniqueProperty()).getSingleResult();
| if (foo1 != null && !foo1.getId().equals(foo.getId)) {
| throw new ValidatorException("Unique Constraint Violation");
| }
| }
| }
In fact, we could have a generic version of this in Seam as part of s:validate.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4059691#4059691
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4059691
More information about the jboss-user
mailing list