Monday, 16 April 2012

Oracle ADF : How to change an attribute value of the read-only iterator's current row

// change attribute value of current row in iterator
DCIteratorBinding iterBind = ADFUtils.findIterator("MyVOIterator");
Row currRow = iterBind.getCurrentRow();
BackingBeanUtils.setRowEditable(currRow);
currRow.setAttribute("MyAttribute", "MY_VALUE");

// commit transaction
iterBind.getDataControl().commitTransaction();


...and for reference purposes, the setRowEditable(Row) utility method:
public static void setRowEditable(Row row) {
    int attribCount = row.getAttributeCount();
    for(int i = 0; i < attribCount; i++) {
      ViewAttributeDefImpl attrDef = (ViewAttributeDefImpl)
              row.getStructureDef().getAttributeDef(i);
      attrDef.setEditable(true);
      attrDef.setSDOHidden(false);
      attrDef.setUpdateableFlag(ViewAttributeDefImpl.UPDATEABLE);
    } 
}

Tuesday, 27 March 2012

Oracle Forms / OraFormsFaces and Automated Testing

Automated testing tools rely on some key software attributes to enable the automatic testing of functionality in software. One of these attributes I recently had to deal with was field or object names for elements which reside in a web page / html page. Well, to be more specific, by default Oracle Forms return numbered record identifiers to the Forms Applet rendering the forms. By setting the record property to the value of "names" it will behave differently by returning the names by which the records are identified.
So, it is as simple as adding a request parameter to the Forms Servlet URL like below:
http://host:9001/forms/frmservlet?config=MyConfig&record=names
Then I would like to conclude in saying I was happy to discover that the OraFormsFaces framework does in fact pass on all request parameters to the Forms Server. Hence, if you append the same record parameter to the OraFormsFaces Forms URL (the one returning the JavaScript Functions) then it eventually sets the record parameter on the Forms Request and subsequently the record names are evident in the final response!!

Wednesday, 14 March 2012

Oracle ADF Query Component : Executing custom code before or after process query

This is more a kind of note to myself. I had to execute custom code specifically after the query component finished querying and returning its results; i.o.w. after the search button was clicked on the ADF query component and subsequently after the processQuery-method was execute. I did it as follow:

  • I added the following method to my backing bean
   public void processQuery(QueryEvent queryEvent) {   
      
// over here you can put your PRE-processQuery custom code.      

       // call the usual method as part of default query processing.
       JSFUtils.resolveMethodExpression("#     {bindings.DefaultMyVOCriteriaQuery.processQuery}",
      null, new Class[]{QueryEvent.class}, new Object[] {queryEvent});   
      

       // over here you can put your POST-processQuery custom code.      
    }

  • I changed the queryListener attribute's value, of my query component to have the value of (referencing backing bean):
 queryListener="#{viewScope.myBackingBean.processQuery}

Wednesday, 15 February 2012

Native OS ping implemented in Java

I've recently had to implement this very handy code to do an operating system dependent native ping. You'll notice I've created an OSType Enumerator type to represent the OS in question. Also, I've implemented two classes to represent the host to be "ping-ed" as well as the ping result. See below...


   private Process constructWindowsOSProcess(Runtime rt, PingHost host)
                throws IOException {
        return rt.exec("ping -n 1 -w "+ host.getTimeout() +" "+host.getNameOrIP());
    }
   
    private Process constructLinuxOSProcess(Runtime rt, PingHost host)

                throws IOException {
        return rt.exec("ping -c 1 -W "+ (host.getTimeout()/1000) +" "+host.getNameOrIP());
    }
   
    private Process constructOSSpecificProcess(Runtime rt, OSType osType,

             PingHost host) throws IOException {
        if (OSType.WINDOWS == osType) {
            return constructWindowsOSProcess(rt, host);
        } else if (OSType.LINUX == osType) {
            return constructLinuxOSProcess(rt, host);
        }
        return constructWindowsOSProcess(rt, host);
    }


    private boolean isReachable(OSType osType, String pingResult) {
        if ((OSType.WINDOWS == osType) && (-1 < pingResult.indexOf(":Reply"))) {
            return true;
        } else if ((OSType.LINUX == osType) && (-1 < pingResult.indexOf("64 bytes from"))) {
            return true;
        }
        return false;
    } 


   /**
     * Pings a host natively with the specified milliseconds(contained in PingHost)

     * as time-out for the ping.
     * @param rt Java Runtime to use in this method
     * @param osType the OS type this code is executing on or should be based on

                              (enum class type)
     * @param host encapsulation of a pingable host and all its attributes.
     * @return PingResult indicating whether the host is reachable or not.
     */
    private PingResult doNativeOSPing(Runtime rt, OSType osType, PingHost host) {
        StringBuffer pingResult = new StringBuffer("");
        try {                       
            Process p = this.constructOSSpecificProcess(rt, osType, host);           
            BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                pingResult.append(inputLine);
            }
            in.close();
           
        } catch (IOException e) {           
            e.printStackTrace();
        }
        return new PingResult(host, this.isReachable(osType, pingResult.toString()));
    }