[jboss-user] [JBoss Seam] - Re: EntityManager in custom validator
shakenbrain
do-not-reply at jboss.com
Wed Apr 25 16:37:41 EDT 2007
Thanks for the quick response. That's fantastic. I think I'm almost there, but I'm not sure how to reference the validator from the page; it's not going to be with the <f:validator> tag, right?
@Name("prefixValidator")
| @Validator
| public class PrefixValidator implements javax.faces.validator.Validator {
|
| @In
| EntityManager entityManager;
|
| @Transactional
| public void validate(FacesContext context, UIComponent component, Object value)
| throws ValidatorException {
|
| entityManager.joinTransaction();
|
| String prefix = (String) value;
|
| Query q = entityManager.createQuery("from Organization o where o.prefix = :prefix");
| q.setParameter("prefix", prefix.toUpperCase());
| if (q.getResultList().size() > 0) {
| throw new ValidatorException(makeMessage("Prefix is being used already"));
| }
| }
| ...
| }
<s:decorate id="prefixDecorator" template="decorateField.xhtml">
| <ui:define name="label">Prefix</ui:define>
| <h:inputText id="prefix" size="4" value="#{organizationEditor.instance.prefix}" required="true" disabled="#{!organizationEditor.new}">
| <f:validator validatorId="prefixValidator"/>
| <a:support event="onblur" reRender="prefixDecorator"/>
| </h:inputText>
| </s:decorate>
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4040742#4040742
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4040742
More information about the jboss-user
mailing list