Monday, 12 August 2013



Property sets are used to define bag of properties or hints that can be used by attributes and bindings .Before going deeper lets first understand about custom properties in ADF model layer.I already have defined this in my previous blog but lets copy and continue -  

------------------------------------------------------------------------------------------------------------
Custom properties are customized name-value pairs that framework can access at run-time.For each attribute of a entity or view object attribute we can define its custom properties which we can  access dynamically at view layer using bindings. 
In this post I am adding custom properties for the EmployeeId attribute for a demo,
Two types of custom properties we can define at model layer: 





"Translatable" custom properties are stored in the resource bundle of the corresponding ADF Business Component. This option is suitable for specifying some custom textual messages, labels, titles, format masks, etc. (which depend on the user's locale) in addition to the standard UI hints, which are supported by the framework out-of-the-box. You should use this option for properties that depend on the user's locale. You can supply locale specific values for these properties by supplying locale specific versions of the corresponding resource bundle.

"Non-translatable" custom properties are stored in the ADF Business Component's XML definition file. As far as this file is not translated (by supplying additional locale specific versions for it), this option should be used for custom properties whose values do not depend on the user's locale.


 See for this sample the XML file entry for the properties are as below - 

 <Properties>
      <CustomProperties>
        <Property
          Name="customReadonly"
          Value="false"/>
        <Property
          Name="customLabel"
          Value="customelabel"/>
        <Property
          Name="customMaxLenth"
          Value="10"/>
        <Property
          Name="customShortDesc"
          Value="customShortDesc"/>
      </CustomProperties>
    </Properties>


When we see the jspx page we see the code looks like -

  <af:inputText value="#{bindings.EmployeeId.inputValue}"
                            label="#{bindings.EmployeeId.hints.label}"
                            required="#{bindings.EmployeeId.hints.mandatory}"
                            columns="#{bindings.EmployeeId.hints.displayWidth}"
                            maximumLength="#{bindings.EmployeeId.hints.precision}"
                            shortDesc="#{bindings.EmployeeId.hints.tooltip}"
                            id="it5">
 <af:convertNumber groupingUsed="false"
                                  pattern="#{bindings.EmployeeId.format}"/>
              </af:inputText>


Lets modify the binding expressions with the custom properties from hints  -

 <af:inputText value="#{bindings.EmployeeId.inputValue}"
                            label="#{bindings.EmployeeId.hints.customLabel}"
                            required="#{bindings.EmployeeId.hints.mandatory}"
                            columns="#{bindings.EmployeeId.hints.displayWidth}"
                            maximumLength="#{bindings.EmployeeId.hints.customMaxLenth}"
                            shortDesc="#{bindings.EmployeeId.hints.customShortDesc}"
                            readOnly="#{bindings.EmployeeId.hints.customReadonly}"
                            id="it5">
                <af:convertNumber groupingUsed="false"
                                  pattern="#{bindings.EmployeeId.format}"/>
              </af:inputText>

Notice the changes we did for tooltip,label and maxlenth -


















Lets proceed and see how can we change this dynamically :
We will write a method in Impl class and will create client interface to expose at UI.

Add this code in EmployeesViewImpl -

     public void setHintsForCustomProperties(){
       
        AttributeDefImpl attr = ((AttributeDefImpl) findAttributeDef("EmployeeId"));
            attr.setProperty("customReadonly", Boolean.FALSE);
            attr.setProperty("customLabel", "This is a demo for label");
        attr.setProperty("customMaxLenth", 20 );
        attr.setProperty("customShortDesc","This is a demo for tooltip");


    }

















Drag and drop the 'setHintsForCustomProperties' operation on page as ADF button ,

Source :  
<af:commandButton actionListener="#{bindings.setHintsForCustomProperties.execute}"
                                text="setHintsForCustomProperties"
                                disabled="#{!bindings.setHintsForCustomProperties.enabled}"
                                id="cb2"/>



Click on the Command button to see the result ,fields are changed  as per the custom properties see in below pic 





















Above we learned about custom properties ,But suppose we need same set of custom properties for  many EO/VO then it is not a good practice to write the same properties again and again ,Instead we can use the advance feature of ADF 'Property Set ' .
We can declare all the custom properties in a property set that are reusable and common for many EO/VO.


------------------------------------------------------------------------------------------------------------


We can create a property set from the New Gallery- 






Lets declare a custom property 'MaxLenthForAll' in  'PropertySetDemo' . 
The xml code change will  be as below -

 <Properties>
    <CustomProperties>
      <Property
        Name="MaxLenthForAll"
        Value="20"/>
    </CustomProperties>

  </Properties>


We can select any attribute on which we want to apply this property set.Here I am applying to same i.e  EmployeeId attribute 





















 Now change the expression code for 'maximumLength' property 

 <af:inputText value="#{bindings.EmployeeId.inputValue}"
                            label="#{bindings.EmployeeId.hints.customLabel}"
                            required="#{bindings.EmployeeId.hints.mandatory}"
                            columns="#{bindings.EmployeeId.hints.displayWidth}"
                            maximumLength="#{bindings.EmployeeId.hints.MaxLenthForAll}"
                            shortDesc="#{bindings.EmployeeId.hints.customShortDesc}"
                            readOnly="#{bindings.EmployeeId.hints.customReadonly}"
                            id="it5">
        
                <af:convertNumber groupingUsed="false"
                                  pattern="#{bindings.EmployeeId.format}"/>
              </af:inputText>

Suppose in case we declare the same name - value pairs in the property set and  in EO/VO,then which one will get precedence? Answer is - The custom properties defined at EO/VO level gets precedence over custom properties of property set  .



Thanks !!!!!

3 comments: