Pages

Thursday, November 19, 2009

Find and Expand all nodes of an ADF Tree

I want to find and expand all nodes of an ADF Tree and I saw an Oracle Forum post of Kenyatta which gave me a nice solution.
First some usefull methods.

private void expandTreeChildrenNode( RichTree rt
, FacesCtrlHierNodeBinding node
, List<Key> parentRowKey) {
ArrayList children = node.getChildren();
List<Key> rowKey;

if ( children != null ) {
for (int i = 0; i < children.size(); i++) {
rowKey = new ArrayList<Key>();
rowKey.addAll(parentRowKey);
rowKey.add(((FacesCtrlHierNodeBinding)children.get(i)).getRowKey());
rt.getDisclosedRowKeys().add(rowKey);
if (((FacesCtrlHierNodeBinding)(children.get(i))).getChildren() == null)
continue;
expandTreeChildrenNode(rt
,(FacesCtrlHierNodeBinding)(node.getChildren().get(i))
, rowKey);
}
}
}

// find a jsf component
private UIComponent getUIComponent(String name) {
FacesContext facesCtx = FacesContext.getCurrentInstance();
return facesCtx.getViewRoot().findComponent(name) ;
}

private UIComponent getUIComponent(UIComponent component,String name ){
List<UIComponent> items = component.getChildren();
for ( UIComponent item : items ) {
UIComponent found = getUIComponent(item,name);
if ( found != null ) {
return found;
}
if ( item.getId().equalsIgnoreCase(name) ) {
return item;
};
}
return null;
}

Now find the ADF tree in a region and expand the main and child nodes of this tree

// get the dymamic region of the main page
RichRegion region = (RichRegion)getUIComponent("dynam1");

if ( region != null) {
// find tree 2 and expand this tree
RichTree rt = (RichTree)getUIComponent(region,"t2");
if ( rt != null ) {
int rowCount = rt.getRowCount();
List<Key> rowKey;
for (int j = 0; j < rowCount; j++) {
// expand the main nodes
FacesCtrlHierNodeBinding node = (FacesCtrlHierNodeBinding)rt.getRowData(j);
rowKey = new ArrayList<Key>();
rowKey.add(node.getRowKey());
rt.getDisclosedRowKeys().add(rowKey);
rt.setRowKey(rowKey);
// expand the child nodes of the main nodes
expandTreeChildrenNode(rt , node, rowKey);
}
}
}

Find an UIComponent in an ADF Task Flow Region

When you want to find an UIComponent (like a Tree) inside an ADF Region you can not use findComponent on the ViewRoot because this will only search for the component in the JSF page and not in the JSF page fragments ( Task Flows). And off course you can use a backing bean to make a binding but I want to find the component by first searching for the right Region in the JSF page and then searching the component inside the Region.

First I need to have some common methods.
// find a jsf component inside the JSF page
private UIComponent getUIComponent(String name) {
  FacesContext facesCtx = FacesContext.getCurrentInstance();
  return facesCtx.getViewRoot().findComponent(name) ;
}

// find a UIComponent inside a UIComponent 
private UIComponent getUIComponent(UIComponent component, String name) {
        if (component != null)
            System.out.println(component.getId());
        
        List<UIComponent> items = component.getChildren();
        Iterator<UIComponent> facets = component.getFacetsAndChildren();

        if  ( items.size() > 0 ) {
          System.out.println("got childern");
          for (UIComponent item : items) {
              UIComponent found = getUIComponent(item, name);
              if (found != null) {
                  return found;
              }
              if (item.getId().equalsIgnoreCase(name)) {
                  return item;
              }
          }
        } else if ( facets.hasNext()) {
            System.out.println("got facets");
            while ( facets.hasNext() ){
              UIComponent facet = facets.next();  
              UIComponent found = getUIComponent(facet, name);
              if (found != null) {
                  return found;
              }
              if (facet.getId().equalsIgnoreCase(name)) {
                  return facet;
              }
            }
        }
        return null;
    }
Now we can find the right Region and then search inside the Region for the ADF Tree
// get the dymamic region of the main page
RichRegion region = (RichRegion)getUIComponent("dynam1");
if ( region != null) {
  // find tree 2 
  RichTree rt = (RichTree)getUIComponent(region,"t2");
  if ( rt != null ) {
    // do your thing
  }   
}
Or you can use the findComponent method after you found the region
// get the dymamic region of the main page
RichRegion region = (RichRegion)getUIComponent("dynam1");
if ( region != null) {
  // find tree 2 
  RichTree rt = (RichTree)region.findComponent("t2");
  if ( rt != null ) {
   // do your thing
  }   
}

Tuesday, November 17, 2009

Soa Suite 11g MDS deploy and removal ANT scripts

With the release of Soa Suite 11g R1 Patch Set 1 Oracle improved the standard ant scripts for MDS deployment and removal. Before PS1 we had an ant example of Clemens.
Basically this is how my ANT scripts works. First add your own metadata folders under the apps folder ( do this in jdeveloper\integration\seed\apps ).

My ANT script will do the following steps for every metadata folder under apps
  • optionally remove the metadata folder from the remote Soa Suite Database MDS repository
  • Make a zip file of the metadata files ( Local MDS file repository) .
  • Make a new Soa Bundle zip with this metadata zip
  • Deploy this soa bundle to the Soa Suite Server, The server will add this to the Database MDS
When you want to use the MDS files in your own project read this blog


To make this work copy the antcontrib jar to the jdeveloper\ant\lib folder ( because of the foreach and the propertycopy fucntion )
Here is my build.properties

The build.xml

and at last the deployMDS.bat file
set ORACLE_HOME=C:\oracle\MiddlewareJdev11gR1PS2
set ANT_HOME=%ORACLE_HOME%\jdeveloper\ant
set PATH=%ANT_HOME%\bin;%PATH%
set JAVA_HOME=%ORACLE_HOME%\jdk160_18

set CURRENT_FOLDER=%CD%

ant -f build.xml deployMDS
See my github for the source code https://github.com/biemond/soa_tools