Saturday, October 20, 2012

How to make Default Command working in JSFF Page in AF:Region in JDeveloper 11g

Oracle JDeveloper 11.1.2.1
ADF Faces Rich Component


This post explain how can you set command button to default command in jsff page exposed in af:Region.

While you use jspx pages, af:form component has property DefaultCommand, when set to id of any af:commandButton, invokes the associated action on pressing Enter Key.

However, when you are using page fragment (jsff) page & exposed in region, using this property from parent page would not give right ID of command button bz of surrounding containers.

So, alternative is to use javascript in jsff page in one of the UI component, when the ENTER button is pressed inside this component, a button action is invoked programmatically.

For Example, jsff page has one af:inputText & one af:commandButton to press:

 <af:panelFormLayout id="pfl1" labelWidth="250">  
   
  <af:resource type="javascript">   
     function onEnterKey(inputevent){   
       if(inputevent.getKeyCode() = AdfKeyStroke.ENTER_KEY {   
        var inputTextId = inputevent.getSource();  
   
         //If inputText & Button reside in same container   
         var reportbtn = inputTextId.findComponent('cb2');           
   
         AdfActionEvent.queue(reportbtn);  
   
         inputevent.cancel(); //stop sending event to server  
   
        }  
   
      }  
   
   </af:resource>  
   
   <af:inputText label="Enter Year" id="it1" maximumLength="4" showRequired="true"   
               requiredMessageDetail="Please Enter Year">   
  
        <af:clientListener method="onEnterKey" type="keyUp"/>   
   </af:inputText>  
   
   <af:panelGroupLayout id="pgl2" layout="horizontal" inlineStyle="width:326px;">   
       <af:commandButton text="Show Report" id="cb2" clientComponent="true"/>     
   </af:panelGroupLayout>  
   
 </af:panelFormLayout>  


Please note that af:clientListener tag for inputText & clientComponent=true property of commandButton should present to work with javascript.