Monday, 12 August 2013

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 





















Thanks

0 comments:

Post a Comment