Tuesday, June 5, 2012

Part1 - Hiding Unwanted Operators in Advanced mode of af:query Component

Oracle ADF helps you to build af:query component declaratively by dropping view criteria defined in a view object on to a page. While building view criteria you can create custom operators or remove built-in operators (displayed in advanced mode of af:query component) for each view criteria item by adding <CompOper/> to the view object XML file. Note that you may need to do it manually, there is no editor support for the same. This concept is explained in developers guide under the topic - How to Create Custom Operators or Remove Standard Operators.

The attributes used in <CompOper/> as as follows:

  • Name: Specify an id for the operation.
  • ToDo: Set to 1 to add this custom operator. Set to -1 to remove an operator.
  • OperDescStrCode: Specify the id used in the message bundle to map to the description string.
  • Oper: Set to a value that will be used programmatically to denote this operation in the SQL statement. 
  • MinCardinality: If there is an input range, set this property to the minimum value for the range. For example, if the range is months in a year, this value should be set to 1. If there is no range, set it to 0.
  • MaxCardinality: If there is an input range, set this property to the maximum value for the range. For example, if the range is months in a year, this value should be set to 12. If there is no range, set it to 0.
  • TransientExpression: Set the expression to perform the custom operator function. 
In the following example operators BETWEEN and NOTBETWEEN are removed for 'Email' ViewCriteriaItem in the advanced mode of af:query component.

  <ViewCriteria  
     Name="EmployeesViewCriteria"  
     ViewObjectName="model.EmployeesView"  
     Conjunction="AND">  
     <Properties>  
       <CustomProperties>  
         <Property  
           Name="displayOperators"  
           Value="InAdvancedMode"/>  
         <Property  
           Name="autoExecute"  
           Value="false"/>  
         <Property  
           Name="allowConjunctionOverride"  
           Value="true"/>  
         <Property  
           Name="showInList"  
           Value="true"/>  
         <Property  
           Name="mode"  
           Value="Basic"/>  
       </CustomProperties>  
     </Properties>  
     <ViewCriteriaRow  
       Name="EmployeesViewCriteria_row_0"  
       UpperColumns="1">  
       <ViewCriteriaItem  
         Name="Email"  
         ViewAttribute="Email"  
         Operator="="  
         Conjunction="AND"  
         Required="Optional">  
         <CompOper  
           Name="Name"  
           Oper="BETWEEN"  
           ToDo="-1"  
           MinCardinality="0"  
           MaxCardinality="0"/>  
         <CompOper  
           Name="Name"  
           Oper="NOTBETWEEN"  
           ToDo="-1"  
           MinCardinality="0"  
           MaxCardinality="0"/>  
       </ViewCriteriaItem>  
       <ViewCriteriaItem  
         Name="EmployeesViewCriteria_EmployeesViewCriteria_row_0_DepartmentId"  
         ViewAttribute="DepartmentId"  
         Operator="="  
         Conjunction="AND"  
         Required="Optional"/>  
     </ViewCriteriaRow>  
 </ViewCriteria>  



Learn More ...

There are a lot more points like this. If  you are curious to learn the internals of the ADF Business Components and ADF Binding Layer,  the following book is for you - Oracle ADF Real World Developer’s Guide.
More details about this book can be found in this post- http://jobinesh.blogspot.in/2012/07/pre-order-your-copy-of-oracle-adf-real.html

Friday, June 1, 2012

Disabling UI Component With ADF Faces JavaScript API

Following example illustrates how to disable UI component using ADF Faces Java Script API. This example disables af:inputText when you click the button.

Note that af:inputText has set unsecure="disabled" and clientComponent="true". You must set these properties appropriately to  set component properties in the client side.

  •  unsecure 


 A whitespace separated list of attributes whose values ordinarily can be set only on the server, but need to be settable on the client. Currently, this is supported only for the "disabled" attribute. Note that when you are able to set a property on the client, you will be allowed to by using the the .setProperty('attribute', newValue) method, but not the .setXXXAttribute(newValue) method. For example, if you have unsecure="disabled", then on the client you can use the method .setProperty('disabled', false), while the method .setDisabled(false) will not work and will provide a javascript error that setDisabled is not a function.


  •  clientComponent

 whether a client-side component will be generated. A component may be generated whether or not this flag is set, but if client Javascript requires the component object, this must be set to true to guarantee the component's presence. Client component objects that are generated today by default may not be present in the future; setting this flag is the only way to guarantee a component's presence, and clients cannot rely on implicit behavior. However, there is a performance cost to setting this flag, so clients should avoid turning on client components unless absolutely necessary.


 <?xml version='1.0' encoding='UTF-8'?>  
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
 <f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">  
   <af:document title="test.jsf" id="d1">  
     <af:resource type="javascript">  
      function disableField(actionEvent) {  
   
        var nameInputText = actionEvent.getSource().findComponent("nameFld");  
        nameInputText.setProperty("disabled", true);  
          
        //The following line is for partial refresh, in this case   
        //its taken care by framework  
        //AdfPage.PAGE.addPartialTargets(nameInputText);  
          
        actionEvent.cancel();  
      }  
   
      function enableField(actionEvent) {  
   
        var nameInputText = actionEvent.getSource().findComponent("nameFld");  
        nameInputText.setProperty("disabled", false);  
        actionEvent.cancel();  
      }  
     </af:resource>  
     <af:form id="f1">  
       <af:panelGroupLayout id="pgl1">  
         <af:commandButton text="Disable Name Field" id="disableBtn" 
                  partialSubmit="true">  
           <af:clientListener type="action" method="disableField"/>  
         </af:commandButton>  
         <af:commandButton text="Enable Name Field" id="enableBtn" 
                  partialSubmit="true">  
           <af:clientListener type="action" method="enableField"/>  
         </af:commandButton>  
       </af:panelGroupLayout>  
       <af:inputText unsecure="disabled" clientComponent="true" label="Name" id="nameFld"/>  
     </af:form>  
   </af:document>  
 </f:view>