« ADF Faces RC: Lucas Jellema about Date/Time input | Main | I’ve been tagged and so I have to unveil private secrets »
ADF Faces RC: Single row / Multi row delete from a tree component
By frank.nimphius | January 10, 2008
The usecase I am covering with this blog entry is singe/multi row delete from a rich tree in ADF Faces RC. Note that this is a raw diamond and for sure will need some polishing to work under all circumstances (e.g. I didn't test the condition in which you delete a node and its children separately. So what happens if the node is deleted before the children). The sample workspace that you can download at the end of this blog was created with JDeveloper 11 TP3 and the database connection is for the HR schema.
![]() |
You press the "ctrl" key and select the rows you want to delete with the mouse. Then you click the delete button to remove the rows from the ADF tree binding. Clicking the commit button persists the changes.
Page source
-
:document> -
:messages/> -
:form> -
:panelStretchLayout styleClass="AFVisualRoot"> -
:facet name="bottom"/> -
:facet name="center"> -
:panelCollection id="panelColllection1"> -
:facet name="menus"/> -
:facet name="toolbar"> -
:toolbar> -
:commandToolbarButton text="#{bundle['TREE.DELETE.MANY.DELETE_MANY']}" -
actionListener="#{MultiRowDeleteBean.onTreeNodeDelete}"
-
id="deleteCommand" partialSubmit="true"/>
-
:commandToolbarButton actionListener="#{bindings.Commit.execute}" -
text="Commit"
-
disabled="#{!bindings.Commit.enabled}"
-
partialTriggers="deleteCommand"/>
-
:toolbar>
-
:facet>
-
:facet name="statusbar"/> -
:tree value="#{bindings.LocationsView1.treeModel}" var="node" -
rowSelection="multiple"
-
binding="#{MultiRowDeleteBean.treeComponent1}" clientComponent="false" partialTriggers="deleteCommand">
-
:facet name="nodeStamp"> -
utputText value="#{node}"/>
-
:facet>
-
:tree>
-
:panelCollection>
-
:facet>
-
:facet name="top"/> -
:facet name="start"/> -
:facet name="end"/> -
:panelStretchLayout>
-
:form>
-
:document>
Managed bean code
-
package adf.sample.view;
-
-
import javax.el.ELContext;
-
import javax.el.ExpressionFactory;
-
import javax.el.ValueExpression;
-
-
import javax.faces.application.Application;
-
import javax.faces.context.FacesContext;
-
import javax.faces.event.ActionEvent;
-
-
import oracle.adf.model.binding.DCBindingContainer;
-
import oracle.adf.view.rich.component.rich.data.RichTree;
-
-
import oracle.adfinternal.view.faces.model.binding.FacesCtrlHierBinding;
-
-
import oracle.jbo.Key;
-
-
import oracle.jbo.Row;
-
import oracle.jbo.uicli.binding.JUCtrlHierNodeBinding;
-
import oracle.jbo.uicli.binding.JUCtrlValueBindingRef;
-
-
import org.apache.myfaces.trinidad.model.RowKeySet;
-
-
-
public class MultiRowDeleteBean {
-
private RichTree treeComponent1;
-
-
public MultiRowDeleteBean() {
-
}
-
-
public void onTreeNodeDelete( actionEvent) {
-
-
FacesContext fctx = FacesContext.getCurrentInstance();
-
Application application = fctx.getApplication();
-
-
ELContext elctx = fctx.getELContext();
-
ExpressionFactory exprfactory = application.getExpressionFactory();
-
-
ValueExpression valueExpression = exprfactory.createValueExpression(elctx,"#{bindings}",.class);
-
DCBindingContainer dcbinding = (DCBindingContainer) valueExpression.getValue(elctx);
-
-
FacesCtrlHierBinding treeRootNode = (FacesCtrlHierBinding) dcbinding.get("LocationsView1");
-
-
RowKeySet rowKeySet = (RowKeySet) treeComponent1.getSelectedRowKeys();
-
-
for ( facesTreeRowKey : rowKeySet) {
-
treeComponent1.setRowKey(facesTreeRowKey);
-
JUCtrlHierNodeBinding rowData = (JUCtrlHierNodeBinding) treeComponent1.getRowData();
-
((JUCtrlHierNodeBinding)treeRootNode.getCollectionModel().getRowData()).getRow().remove();
-
}
-
}
-
-
public void setTreeComponent1(RichTree treeComponent1) {
-
this.treeComponent1 = treeComponent1;
-
}
-
-
public RichTree getTreeComponent1() {
-
return treeComponent1;
-
}
-
}
As you see in the managed bean code, I am looking up the tree binding in the pageDef file, which in this case is named "LocationsView1". I also created a property binding of the tree component's "binding" property to the managed bean to get a hold of the tree instance. From the tree I read the selected tree rows (or, better to say, the selected nodes and leaves).
To obtain the ADF binding refreces for the selected tree nodes, the tree selection state needs to be translated to the underlying binding's row key. I took this part of the code from Steve Muench's paper about migrating ADF Faces in JDeveloper 10.1.3 to Trinidad in JDeveloper 11. I must admit that it was the eye opener on the challenge that I worked on longer than I wanted
The rest is a piece of cake: Get the tree binding reference and remove the selected row from its collection model.
Download the workspace here!
Frank
Topics: ADF Faces RC | No Comments »
Comments are closed.