The af:setPropertyListener comes very handy when we use af:iterator and need some processing to be done on an event fired by a component within the iterator.
af:iterator dynamically creates the multiple component instances of the component defined within in during design time. If we want to do some processing on event handling of a component instance within that, af:setPropertyListener is very useful.
Consider a scenario where we have a list of booleans to be rendered in a UI page. We can use af:iterator as below:
<af:panelGroupLayout id="pgl8" layout="vertical">
<af:iterator id="i1" value="#{pageFlowScope.accessGroups}"
var="accessGroup">
<af:selectBooleanCheckbox text="#{accessGroup.name}"
value="#{accessGroup.selected}"
label=""
id="sbc1" autoSubmit="true"
disabled="#{ !accessGroup.canModify}"
rendered="#{accessGroup ne null}"
valueChangeListener="#{myBean.onSelectionChangeOfAccessGroup}">
<af:setPropertyListener from="#{accessGroup.name}"
to="#{requestScope.selChangedAccessGroupName}"
type="valueChange"/>
</af:selectBooleanCheckbox>
</af:panelGroupLayout>
In the above example, the iterator iterates over the collection of booleans accessGroups. As per the layout in which it is contained, we get n checkboxes vertically aligned for n entries in the collection.
If the user wants to change a particular checkbox selection and do some processing on the value change of that checkbox by depending on the instance of accessGroup's other attributes, it is definitely necessary to have a reference of that accessGroup instance which is impossible to to know during the design time. Hence I used setPropertyListener to capture the accessGroup instance into a requestScope variable "selChangedAccessGroupName". I will use this in my event handling logic to do some processing as per the requirement. Sample code shown below.
myBean.java:
public class myBean implements Serializable{
public void onSelectionChangeOfAccessGroup(valueChangeEvent e){
AccessGroup ag = ADFContext.getCurrent().getRequestScope().get("selChangedAccessGroupName")
if(e.getNewValue){
// Invoke business service method by passing ag.getName() and e.getNewValue
}
}
}
The setPropertyListener from attribute is configured with value to be read and to attribute captures it into a requestScope variable. The type attribute is configured with event when the value need to be captured. This type attribute can be changed to different event types based on the requirement.
af:iterator dynamically creates the multiple component instances of the component defined within in during design time. If we want to do some processing on event handling of a component instance within that, af:setPropertyListener is very useful.
Consider a scenario where we have a list of booleans to be rendered in a UI page. We can use af:iterator as below:
<af:panelGroupLayout id="pgl8" layout="vertical">
<af:iterator id="i1" value="#{pageFlowScope.accessGroups}"
var="accessGroup">
<af:selectBooleanCheckbox text="#{accessGroup.name}"
value="#{accessGroup.selected}"
label=""
id="sbc1" autoSubmit="true"
disabled="#{ !accessGroup.canModify}"
rendered="#{accessGroup ne null}"
valueChangeListener="#{myBean.onSelectionChangeOfAccessGroup}">
<af:setPropertyListener from="#{accessGroup.name}"
to="#{requestScope.selChangedAccessGroupName}"
type="valueChange"/>
</af:selectBooleanCheckbox>
</af:panelGroupLayout>
In the above example, the iterator iterates over the collection of booleans accessGroups. As per the layout in which it is contained, we get n checkboxes vertically aligned for n entries in the collection.
If the user wants to change a particular checkbox selection and do some processing on the value change of that checkbox by depending on the instance of accessGroup's other attributes, it is definitely necessary to have a reference of that accessGroup instance which is impossible to to know during the design time. Hence I used setPropertyListener to capture the accessGroup instance into a requestScope variable "selChangedAccessGroupName". I will use this in my event handling logic to do some processing as per the requirement. Sample code shown below.
myBean.java:
public class myBean implements Serializable{
public void onSelectionChangeOfAccessGroup(valueChangeEvent e){
AccessGroup ag = ADFContext.getCurrent().getRequestScope().get("selChangedAccessGroupName")
if(e.getNewValue){
// Invoke business service method by passing ag.getName() and e.getNewValue
}
}
}
The setPropertyListener from attribute is configured with value to be read and to attribute captures it into a requestScope variable. The type attribute is configured with event when the value need to be captured. This type attribute can be changed to different event types based on the requirement.