We should use ComponentReference if we need to have a reference to an instance of the UIComponent class in managed bean that are longer than requested scoped.
Example:
Following code will be generated by default in managed bean when we create binding for UIComponent.
import oracle.adf.view.rich.component.rich.output.RichOutputText;
private RichOutputText acctId;
public void setAcctId(RichOutputText acctId) {
this.acctId = acctId;
}
public RichOutputText getAcctId() {
return acctId;
}
And this can be rewritten using ComponentReference as shown below.
import oracle.adf.view.rich.component.rich.output.RichOutputText;
import org.apache.myfaces.trinidad.util.ComponentReference;
private ComponentReference acctId;
public void setAcctId(RichOutputText acctId) {
this.acctId =
ComponentReference.newUIComponentReference(acctId);
}
public RichOutputText getAcctId() {
if (acctId != null) {
return (RichOutputText)acctId.getComponent();
}
return null;
}
Detailed explanation about ComponentReference can be found in following links.
http://myfaces.apache.org/trinidad/trinidad-api/apidocs/org/apache/myfaces/trinidad/util/ComponentReference.html
http://docs.oracle.com/cd/E16162_01/web.1112/e16181/gs_jdev.htm
Example:
Following code will be generated by default in managed bean when we create binding for UIComponent.
import oracle.adf.view.rich.component.rich.output.RichOutputText;
private RichOutputText acctId;
public void setAcctId(RichOutputText acctId) {
this.acctId = acctId;
}
public RichOutputText getAcctId() {
return acctId;
}
And this can be rewritten using ComponentReference as shown below.
import oracle.adf.view.rich.component.rich.output.RichOutputText;
import org.apache.myfaces.trinidad.util.ComponentReference;
private ComponentReference acctId;
public void setAcctId(RichOutputText acctId) {
this.acctId =
ComponentReference.newUIComponentReference(acctId);
}
public RichOutputText getAcctId() {
if (acctId != null) {
return (RichOutputText)acctId.getComponent();
}
return null;
}
Detailed explanation about ComponentReference can be found in following links.
http://myfaces.apache.org/trinidad/trinidad-api/apidocs/org/apache/myfaces/trinidad/util/ComponentReference.html
http://docs.oracle.com/cd/E16162_01/web.1112/e16181/gs_jdev.htm
Cool, informative...
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteOnly I would use a generic version of ComponentReference, so ComponentReference<RichOutputText> acctld instead of ComponentReference acctld
ReplyDelete