Monday, September 12, 2016

Modify Row hints on the fly

Scenario - Recently we had a use case where Same View Object is used in 3 different places and the label value of a field should be dynamically calculated based on the context.

Eg: Lets say, In Employee and Departments table,
the in the Employee Entry Form should say

Engineer Name : <Input Text>
HR Name: <Input Text>
GM Name: <Input Text>

based on the chosen Employee type.

Note: the above is just a sample to explain the scenario not the exact use case.

Solution- It can be implemented by EL expressions etc, but it may get clumsy and had to be done in multiple places as employee type grows.

Instead we modified label hints on the fly.

How to do it?

Override the createViewRowAttrHints in ViewRowImpl

    @Override
    protected ViewRowAttrHintsImpl createViewRowAttrHints(AttributeDefImpl attrDef) {
      return new CustomRowAttrHintsImpl(attrDef, this);
    }

Override getLabel in CustomRowAttrHintsImpl as shown below.
You could see there are options to override other hints such as Tooltip,DisplayHeight etc


 import oracle.jbo.AttributeHints;  
 import oracle.jbo.LocaleContext;  
 import oracle.jbo.server.AttributeDefImpl;  
 import oracle.jbo.server.ViewRowAttrHintsImpl;  
 import oracle.jbo.server.ViewRowImpl;  
 public class CustomRowAttrHintsImpl extends ViewRowAttrHintsImpl {  
   public CustomRowAttrHintsImpl(AttributeDefImpl attributeDefImpl, ViewRowImpl viewRowImpl) {  
     super(attributeDefImpl, viewRowImpl);  
   }  
   public CustomRowAttrHintsImpl() {  
     super();  
   }  
   @Override   
    public String getLabel(LocaleContext locale) {   
     if (("EmployeeName").equalsIgnoreCase(getViewAttributeDef().getName())) {   
      String EmployeeCode= (String)getViewRow().getAttribute("EmployeeCode");   
      if (EmployeeCode!= null || !EmployeeCode.equalsIgnoreCase("") || EmployeeCode.equalsIgnoreCase("IT"))   
       return "Engineer";   
      else  if (EmployeeCode.equalsIgnoreCase("HR"))  
       return "HR";   
     }   
     return super.getLabel(locale);   
    }  
   @Override   
    public String getTooltip(LocaleContext locale) {   
     return super.getTooltip(locale);   
    }  
   @Override   
    public String isAutoSubmit(LocaleContext locale) {   
     return super.getTooltip(locale);   
    }  
   @Override   
    public String getDisplayHeight(LocaleContext locale) {   
     return super.getTooltip(locale);   
    }  
   @Override   
    public String getDisplayWidth(LocaleContext locale) {   
     return super.getTooltip(locale);   
    }  
   @Override   
    public String getDisplayHint(LocaleContext locale) {   
     return super.getTooltip(locale);   
    }  
 }  

Hope it helps.. :-)

4 comments:

  1. Great content thank you for sharing

    from

    oracle fusion

    ReplyDelete
  2. Regards
    Sridevi Koduru (Senior Oracle Apps Trainer Oracleappstechnical.com)
    LinkedIn profile - https://in.linkedin.com/in/sridevi-koduru-9b876a8b
    Please Contact for One to One Online Training on Oracle Apps Technical, Financials, SCM, SQL, PL/SQL, D2K at training@oracleappstechnical.com | +91 - 9581017828.

    ReplyDelete