Oracle ADF Code Corner: ADF Quickies 2009

ADF Quickies 2009

Some solutions are too small to blog or write an article about. I created this page for code examples like these that don't require a sample workspace. This way nothing gets lost!.

Written by Frank Nimphius, Oracle Corporation

 

af:query
 

Problem:

The af:query component renders a number spin box for numeric search attributes. How can I restrict the the field so the user cannot choose a negative value ?

Solution:

The af:query component is built out of other components, one of which is the af:InputNumberSpinbox. You can use the code shown below to parse the af:query component for its child components. It stops for occurences of af:InputNumberSpinbox and sets the maximum and minimum value you specify.

private void setAdfQueryNumberSpinRange(UIComponent component, Integer min, Integer max){
List<UIComponent> list = component.getChildren();
for (UIComponent com : list){
if (!(com instanceof RichInputNumberSpinbox)){
setAdfQueryNumberSpinRange(com,min,max);
}
else{
if (min != null){
((RichInputNumberSpinbox)com).setMinimum(min);
}
if(max != null){
((RichInputNumberSpinbox)com).setMaximum(max);
}
}
}
}

You call this method from a managed bean and pass it an instance of RichQuery that you ceate through a HSF component binding. As you can see, this code only is the start because it allows you to custoimze a lot more than the number spin box.

 

af:CommandButton
 

Problem:

Invoke a command button from JavaScript on the browser client

Solution:

The client side framework in ADF Faces RC allows you to qeue the action of a component to be exected on the server.

function callRefreshButton(){
var buttton1 =AdfPage.PAGE.findComponentByAbsoluteId("refreshButton");
ActionEvent.queue(button1,true);
}

When calling this JavaScript function from anywhere on the page, it searches the button by absolute id and queues the action on it. If the button is hidden, then you better use the serverListener component instead.

 


ADF Business Components
 

Problem:

You need to get the JDBC URL of an ADF BC bound ADF application.

Solution:

The JDBC connection can be accessed from the transaction in ADF Business Components. The code below is used from the ApplicationModuleImpl method. .

DBTransaction transaction = this.getDBTransaction();
PreparedStatement preparedStatement = transaction.createPreparedStatement("commit;",0);
Connection conn;

try {
  conn = preparedStatement.getConnection();
  System.out.println(" ---- "+conn.getMetaData().getURL());
} catch (SQLException e) {
  e.printStackTrace();
}
    

Note that the commit operation is not executed. It is only used to create the statement.

 

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy