1 2 Previous Next 18 Replies Latest reply on Apr 3, 2009 10:43 AM by jeremygood

    <a4j:support> not working

      I 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


        • 1. Re: <a4j:support> not working
          ilya_shaikovsky

          which seam and RF version you using? As you could check at our demo - we're working fine with Hibernate validators.. even without seam by using own components like s:validate.

          • 2. Re: <a4j:support> not working

            I'm using Seam 2.1.1.GA. How would I determine what version of richfaces I'm using?

            As for the RichFaces demo, that page no longer works for me. It did up until a few days ago. Now I get lots of JavaScript errors when I bring it up, and then I am unable to open any of the sections on the left.

            The first JS error is: Error: Richfaces is not defined
            Source File: http://livedemo.exadel.com/richfaces-demo/richfaces/scrollableDataTable.jsf?c=scrollableDataTable&tab=usage
            Line: 1138

            which is this line:

            </table></td></tr></tbody></table></div></div><input id="j_id109_panelBarInput" name="j_id109" type="hidden" value="richDataIterators" /><script type="text/javascript">new Richfaces.PanelBar('j_id109',{'onitemchange':'','mousemove':'','items':[{'onleave':'','id':'ajaxSupport','onenter':''} ,{'onleave':'','id':'ajaxResources','onenter':''} ,{'onleave':'','id':'richValidators','onenter':''} ,{'onleave':'','id':'ajaxOutput','onenter':''} ,{'onleave':'','id':'ajaxMisc','onenter':''} ,{'onleave':'','id':'richDataIterators','onenter':''} ,{'onleave':'','id':'richDragDrop','onenter':''} ,{'onleave':'','id':'richMenu','onenter':''} ,{'onleave':'','id':'richTree','onenter':''} ,{'onleave':'','id':'richOutputs','onenter':''} ,{'onleave':'','id':'richInputs','onenter':''} ,{'onleave':'','id':'richSelect','onenter':''} ,{'onleave':'','id':'richMisc','onenter':''} ] ,'mouseout':'','ajax':false,'mouseover':'','onclick':''} );</script></div></div></div>
            


            • 3. Re: <a4j:support> not working
              ilya_shaikovsky
              • 4. Re: <a4j:support> not working

                My initial response would be no. I am having trouble seeing any similarities.

                • 5. Re: <a4j:support> not working
                  nbelaevski

                   

                  "ilya_shaikovsky" wrote:
                  which seam and RF version you using? As you could check at our demo - we're working fine with Hibernate validators.. even without seam by using own components like s:validate.

                  Ilya, it's 3.2.2.SR1 - see code in pastebin.

                  • 6. Re: <a4j:support> not working
                    nbelaevski

                    Does this work if you remove ajaxSingle="true"?

                    • 7. Re: <a4j:support> not working

                      Nope. Same results. Here's the HTML. Note that this HTML includes the error message that shows up ONLY afterl the form is submitted.

                      BTW: since I'm having other richfaces troubles with firefox, I also verified that this form exhibits the same behavior on IE 8.0.

                      <div class="label errors"><label for="contentForm:shortNameField:shortName">
                      
                       <span id="contentForm:shortNameField:j_id30">Short Name</span>
                       <span id="contentForm:shortNameField:j_id32" class="required">*</span></label>
                       </div>
                       <span><input id="contentForm:shortNameField:shortName"
                       name="contentForm:shortNameField:shortName" value="a" class="inField"
                       onblur="A4J.AJAX.Submit('_viewRoot','contentForm',event,{'parameters':
                       {'contentForm:shortNameField:shortNameCheck':
                       'contentForm:shortNameField:shortNameCheck'} ,
                       'actionUrl':'/rCMS/editCoupon.seam'} )"
                       style="width: 180px;" type="text">
                       </span>
                       <span class="error">
                       <img src="/rCMS/img/error.gif" class="errors">
                       <span class="errors">length must be between 2 and 32</span>
                       </span></div>
                      


                      • 8. Re: <a4j:support> not working
                        nbelaevski

                        Just to be sure: can you please add rich:messages and check?

                        • 9. Re: <a4j:support> not working

                          Interesting, the rich:message does show up immediately when the field loses focus. But the s:message does not.

                          Also, the error.gif image does not show up until the form is submitted. The image display is triggered by the invalid context value: rendered="#{invalid}"

                          • 10. Re: <a4j:support> not working
                            nbelaevski

                            You should either reRender s:message explicitly or enclose them into a4j:outputPanel having ajaxRendered="true".

                            • 11. Re: <a4j:support> not working
                              ilya_shaikovsky

                               

                              You should either reRender s:message explicitly


                              It means by reRender their parent. As the messages should be inserted after such request.

                              • 12. Re: <a4j:support> not working

                                Ok, I've done that. Now unfortunately, the #{invalid} context value is still not getting set, which means the error.gif image is not showing up and the conditional styles are not being applied (i.e. so the field name is red). The error and the field name are both inside the a4j:outputPanel.

                                Also, is there some way to keep the focus in the field with the error?

                                If this is what must be done to get live validation to work, then Seam in Action is pretty misleading. I copied my edit.xhtml code from the example on page 89.

                                I will do some more reading in the RF Dev Guide and the Live Demo and see if I can't figure this out.

                                Thanks,
                                Jeremy

                                • 13. Re: <a4j:support> not working

                                  Well I've done some reading and some searching, and I cannot find any references to this problem. The problem has now changed a bit in scope, so let me restate it.

                                  a4j:support action does result in setting #{invalid} context variable when Hibernate field validation fails.

                                  Does anyone have a quick answer for me or should I post this in a different forum?

                                  Thanks,
                                  Jeremy

                                  • 14. Re: <a4j:support> not working

                                    Whoops, should say:

                                    a4j:support action does NOT result in setting #{invalid} context variable when Hibernate field validation fails.

                                    Also, I've discovered the #{required} variable seems to get "unset" during ajax validation.

                                    1 2 Previous Next