Monday, 17 October 2016

af:form default command use-case

   Recently I've done some simple application. As usually, there was a logging page, which I have developed following rules from the documentation. The mechanisms were working fine, but there was one user who has pointed a change request - he wanted to facilitate the logging in process. Now he need to use a mouse to click the button, instead he wants the form to be submitted with Enter key. Useful change, to improve user experience with the app I should start with the login page. 

   I've been checking for <af:commandButton> properties in order to find an attribute that would solve it. Unfortunately there was nothing suitable, and, it is not a place for specifying default action. In many cases developers may set such property to more than one components. During short and temporary insanity I've thought about JavaScript function to do the work :)

   Fortunately there is a solution. Simple and quick. Similar to rendered attribute, it is not the component that should be triggered in order to present (or hide) itself. It is the container. There is an attribute, defaultCommand, which must be set in <af:form> tag. And that's it :)

   And short quick note at the end - it supports EL expressions, so the action may be parameterized.


  1. Hi,

    problem is that it doesn't work when your component is inside a region. You have to "hack" it with dirty workaround.


    1. Have you tried with within a region? - it looks it supports the defaultCommand too.

    2. True, maybe your article should reflect that instead of a comment ;)

  2. af:subform works perfectly in page fragments.