3 Replies Latest reply on Aug 13, 2007 10:49 PM by matt.drees

    Seam + Ajax4JSF

    pdhaigh

      Hi,

      I'm using seam with a4j for dynamic validation etc etc. However, all of my a4j enabled parts of the form are actually written to the database on every change.

      E.g.

       <h:form id="webpageForm">
       <f:facet name="afterInvalidField">
       <h:panelGroup><s:message/></h:panelGroup>
       </f:facet>
       <f:facet name="aroundInvalidField">
       <s:span styleClass="error"/>
       </f:facet>
       <s:validateAll>
       <h:panelGrid columns="2" columnClasses="object, value">
      
      
       <h:outputText value="Banner #1"/>
       <h:panelGroup id="smallimage1">
       <s:decorate>
       <h:selectOneMenu value="#{webpage.banner_image_1}" required="true">
       <a4j:support event="onchange" reRender="smallimage1" ajaxSingle="true"/>
       <s:selectItems value="#{bannerImages.resultList}"
       var="image" noSelectionLabel="Please select"
       label="#{image.filename}: #{image.altText}"/>
       <s:convertEntity/>
       </h:selectOneMenu>
       </s:decorate>
       <br/>
       <h:graphicImage value="../images/#{webpage.banner_image_1.filename}" alt="#{webpage.banner_image_1.altText}"></h:graphicImage>
       </h:panelGroup>
      


      Changing the drop down will result in the database entry being updated instantly. Can someone tell me why this is the case, and what I need to do (or have missed doing) to prevent it? I want the model to be updated, naturally, but the database should only be written to when I tell it to..

      phil

        • 1. Re: Seam + Ajax4JSF
          fernando_jmt

          If you are using a conversation you can start it using manual flush mode.

          @Begin(flushMode = FlushModeType.MANUAL)
           public String select(User instance) {
           user = em.find....
           return result;
           }
          
          
           @End
           public String create() {
           em.merge(user);
           em.flush();
           return result;
           }
          
          
          


          HTH.

          • 2. Re: Seam + Ajax4JSF
            pdhaigh

            thanks,

            is there a way to set the flush mode globally?

            • 3. Re: Seam + Ajax4JSF
              matt.drees

              An alternative is to set bypassUpdates="true" on your a4j:support tag. You'll still get a flush, but the model won't have changed.

              I tend to use both flushMode = manual and bypassUpdates.