<a4j:support> not working
jeremygood Mar 30, 2009 7:25 PMI am trying to do live validation as specified in Seam in Action. I am just trying it on one field at the moment. The field is a shortName String field that I've set up with Hibernate validation annotations to be non null and between 2 and 32 characters in length.
If you want to go straight to the generated html, scroll down to the bottom of this message. I've included the relevant snippet and pastebin'ed the rest.
The validation works when I submit the form (see the screenshot below), but IT DOES NOT WORK when the field loses focus. Firefox Web Developerreports no JavaScript errors when I enter, edit, or exit the field, or when I submit the form. There are only some css warnings in the error console.
[img]http://images.quickblogcast.com/9/7/3/3/2/131914-123379/screenshot_14.jpg[/img]
Here's a snippet from the view:
<s:decorate id="shortNameField" template="edit.xhtml"> <ui:define name="label">Short Name</ui:define> <h:inputText styleClass="inField" id="shortName" value="#{editCoupon.shortName}" style="width: 180px;" required="true"> <a4j:support id="shortNameCheck" event="onblur" reRender="shortName" ajaxSingle="true" bypassUpdates="true"/> <s:validate/> </h:inputText> </s:decorate>
Here's the edit template in its entirety
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:a="http://richfaces.org/a4j" xmlns:h="http://java.sun.com/jsf/html"> <s:div> <div class="label #{invalid ? 'errors' : ''}"> <s:label> <s:span><ui:insert name="label"/></s:span> <s:span styleClass="required" rendered="#{required}">*</s:span> </s:label> </div> <span> <s:validateAll> <ui:insert styleClass="value #{invalid ? 'errors' : ''}"/> </s:validateAll> </span> <span class="error"> <h:graphicImage value="/img/error.gif" rendered="#{invalid}" styleClass="errors"/> <s:message styleClass="errors"/> </span> </s:div> </ui:composition>
and here's a snippet from the entity bean
@SuppressWarnings("serial") @Entity @Name("coupon") public class Coupon implements Serializable { private Long id; private String shortName; ... @Id @GeneratedValue public Long getId() { return id; } public void setId(Long id) { this.id = id; } @Length(min=2, max=32) @NotNull public String getShortName() { return shortName; } public void setShortName(String shortName) { this.shortName = shortName; } ... @Remove public void destroy() {} }
Here is the HTML source snippet showing the AJAX onblur code. I inserted some line breaks and indentation to make it readable.
<span> <input id="contentForm:shortNameField:shortName" type="text" name="contentForm:shortNameField:shortName" value="Buy a taco, get a taco" class="inField" onblur="A4J.AJAX.Submit('_viewRoot','contentForm',event, {'parameters':'ajaxSingle':'contentForm:shortNameField:shortName', 'contentForm:shortNameField:shortNameCheck':'contentForm:shortNameField:shortNameCheck'} , 'actionUrl':'/rCMS/editCoupon.seam','control':this} )" style="width: 180px;" /> </span>
The entire generated HTML source can be seen here: http://pastebin.com/m1dc1eb56
Thanks again,
Jeremy Goodell