2 Replies Latest reply on Apr 12, 2007 5:57 PM by Mike Quilleash

    Ajax4jsf and custom event handlers

    Mike Quilleash Newbie

      Hi all.

      I've found playing with the repeater example that specifying your own onXXX events will prevent a4j:support from working. Example

      <h:form>
       <h:panelGrid columns="2">
       <h:outputText value="Type the Text:"/>
       <h:inputText value="#{testBean.text}" onkeyup="">
       <a4j:support event="onkeyup" reRender="repeater"/>
       </h:inputText>
      
       <h:outputText value="Text in the AJAX Response:"/>
       <h:outputText id="repeater" value="#{testBean.text}"/>
      
       </h:panelGrid>
      </h:form>
      


      Specifying an onkeyup explicitly on the inputText will stop ajax4jsf from applying its own event handler logic. Is this intended behaviour?

      I have a requirement to highlight mandatory fields in a different colour and then change when something is typed in. I'm not sure how I can achieve this and have ajax behaviour on controls at the same time.

      Cheers.

      Mike.

        • 1. Re: Ajax4jsf and custom event handlers
          Sergey Smirnov Master

          You can use onkeydown or onkeypress

          Also, a4j:support 'this' points to the input field object. So, you can manipulate with input field style right from the onsubmit like this:

          <h:form>
           <h:panelGrid columns="2">
           <h:outputText value="Type the Text:"/>
           <h:inputText value="#{testBean.text}">
           <a4j:support
           onsubmit="if (this.value!=''){this.style.backgroundColor='white'} else {this.style.backgroundColor='#FFCCCC'}"
           event="onkeyup" reRender="repeater"/>
           </h:inputText>
          
           <h:outputText value="Text in the AJAX Response:"/>
           <h:outputText id="repeater" value="#{testBean.text}"/>
          
           </h:panelGrid>
          </h:form>


          • 2. Re: Ajax4jsf and custom event handlers
            Mike Quilleash Newbie

            Thanks for the reply.

            Would it be possible to somehow merge the code in the event handlers together when AjaxSupport generates its event string?