4 Replies Latest reply on Jul 28, 2008 10:45 AM by Eric H

    a4j:commandButton and making sure an action gets called

    Eric H Novice

      Let's say I have a form like this:


      <h:form>
      Your phone number: <h:inputText value="#{user.phoneNumber}"/>
      <a4j:commandButton action="#{userManager.validateNumber}" value="Update!"/>
      </h:form>



      This form works nicely.  The userManager.validateNumber method can check to see if the phone number is valid (maybe we only want certain area codes) and if it is not acceptable, it can add a message to the FacesMessages, so the apply values phase won't happen.


      But what if we do this:


      <h:form>
      Your phone number: <h:inputText value="#{user.phoneNumber}"/>
      <a4j:commandButton value="Update!"/>
      </h:form>



      The a4j:commandButton updates the values in the object.  No method is called.  Assuming that the user object is part of the SMPC, the changes will also be flushed to the DB.


      Now here is the question:


      If I use the form like the first one, which does contain a method which is called when the button is clicked, is there anything that enforces that that method must be called?  In other words, if some clever user wanted to update the value in the DB while bypassing the method invocation, could that be done somehow?


      I hope this question makes sense.