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
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.. :-)