Overriding labels and Tooltip of input list of value programatically in ADF
Scenario: Suppose you have a LOV which has already labels and tootip for the attributes present in LOV.
Now you have some requirements like you have to reuse this LOV but the labels and tooltip must be different. This you can handle programatically also.
Suppose we have some labels and tooltip already for LOV as follows:
Now suppose you want the labels and tooltip for Dept. Id. should be "Department Number" and "For Dept. Name should be "Department Name".
In order to this you have to do following steps:
1. Create your bean class says LOVBean.
2. Override "launchPopupListener" in inputListOfValues as follows:
<af:inputListOfValues id="departmentIdId"
popupTitle="Search and Select: #{bindings.DepartmentId.hints.label}"
value="#{bindings.DepartmentId.inputValue}"
label="#{bindings.DepartmentId.hints.label}"
model="#{bindings.DepartmentId.listOfValuesModel}"
required="#{bindings.DepartmentId.hints.mandatory}"
columns="#{bindings.DepartmentId.hints.displayWidth}"
shortDesc="#{bindings.DepartmentId.hints.tooltip}"
launchPopupListener="#{backingBeanScope.LOVBean.launchDeptLOV}">
<f:validator binding="#{bindings.DepartmentId.validator}"/>
<af:convertNumber groupingUsed="false"
pattern="#{bindings.DepartmentId.format}"/>
</af:inputListOfValues>
3. Write the following code in "launchDeptLOV" method of bean.
public void launchDeptLOV(LaunchPopupEvent launchPopupEvent) {
BindingContext bctx = BindingContext.getCurrent();
BindingContainer bindings = bctx.getCurrentBindingsEntry();
JUCtrlListBinding lov = (JUCtrlListBinding)bindings.get("DepartmentId");
ViewCriteriaManager vcm = lov.getListIterBinding().getViewObject().getViewCriteriaManager();
vcm.removeViewCriteria(vcm.DFLT_VIEW_CRITERIA_NAME);
ViewCriteria vc = new ViewCriteria(lov.getListIterBinding().getViewObject());
vc.setName(vcm.DFLT_VIEW_CRITERIA_NAME);
ViewObject vo = lov.getListIterBinding().getViewObject();
AttributeDefImpl attrDef = (AttributeDefImpl)vo.findAttributeDef("DepartmentId");
attrDef.setProperty(attrDef.ATTRIBUTE_LABEL, "Department Number");
attrDef.setProperty(attrDef.ATTRIBUTE_TOOLTIP,"Department Number");
AttributeDefImpl attrDef2 = (AttributeDefImpl)vo.findAttributeDef("DepartmentName");
attrDef2.setProperty(attrDef2.ATTRIBUTE_LABEL,"Department Name");
attrDef2.setProperty(attrDef2.ATTRIBUTE_TOOLTIP,"Department Name");
}
Now when you run your page and open the LOV you can see that labels and tooltip for both the attributes got changed.
Now you have some requirements like you have to reuse this LOV but the labels and tooltip must be different. This you can handle programatically also.
Suppose we have some labels and tooltip already for LOV as follows:
In order to this you have to do following steps:
1. Create your bean class says LOVBean.
2. Override "launchPopupListener" in inputListOfValues as follows:
<af:inputListOfValues id="departmentIdId"
popupTitle="Search and Select: #{bindings.DepartmentId.hints.label}"
value="#{bindings.DepartmentId.inputValue}"
label="#{bindings.DepartmentId.hints.label}"
model="#{bindings.DepartmentId.listOfValuesModel}"
required="#{bindings.DepartmentId.hints.mandatory}"
columns="#{bindings.DepartmentId.hints.displayWidth}"
shortDesc="#{bindings.DepartmentId.hints.tooltip}"
launchPopupListener="#{backingBeanScope.LOVBean.launchDeptLOV}">
<f:validator binding="#{bindings.DepartmentId.validator}"/>
<af:convertNumber groupingUsed="false"
pattern="#{bindings.DepartmentId.format}"/>
</af:inputListOfValues>
3. Write the following code in "launchDeptLOV" method of bean.
public void launchDeptLOV(LaunchPopupEvent launchPopupEvent) {
BindingContext bctx = BindingContext.getCurrent();
BindingContainer bindings = bctx.getCurrentBindingsEntry();
JUCtrlListBinding lov = (JUCtrlListBinding)bindings.get("DepartmentId");
ViewCriteriaManager vcm = lov.getListIterBinding().getViewObject().getViewCriteriaManager();
vcm.removeViewCriteria(vcm.DFLT_VIEW_CRITERIA_NAME);
ViewCriteria vc = new ViewCriteria(lov.getListIterBinding().getViewObject());
vc.setName(vcm.DFLT_VIEW_CRITERIA_NAME);
ViewObject vo = lov.getListIterBinding().getViewObject();
AttributeDefImpl attrDef = (AttributeDefImpl)vo.findAttributeDef("DepartmentId");
attrDef.setProperty(attrDef.ATTRIBUTE_LABEL, "Department Number");
attrDef.setProperty(attrDef.ATTRIBUTE_TOOLTIP,"Department Number");
AttributeDefImpl attrDef2 = (AttributeDefImpl)vo.findAttributeDef("DepartmentName");
attrDef2.setProperty(attrDef2.ATTRIBUTE_LABEL,"Department Name");
attrDef2.setProperty(attrDef2.ATTRIBUTE_TOOLTIP,"Department Name");
}
Now when you run your page and open the LOV you can see that labels and tooltip for both the attributes got changed.
Comments
Post a Comment