Friday, March 2, 2012

Free Advanced ADF course

Great news! Oracle now provides free online training for ADF. According to Grant Ronald's blog, more parts of this course will be released in the coming weeks.

Get started, or sharpen your ADF skills...

ADF 11g: Select date and time

Today, I had to enable the users to not only select a date, but also a time. I remember this being a lot of work in 10g, but in 11g, it's apparantly out of the box functionality.

Thanks to Shay Shmeltzer for providing a solution!

https://blogs.oracle.com/shay/entry/a_timehour_selector_in_adf_fac

In short:
  • Make field in database of type TIMESTAMP
  • Make sure it's also a TIMESTAMP in your entity object
  • Provide a date format mask that includes hours and minutes


More information can also be found in this forum thread.

Java7 features

Java 7 has been released for a while now, but I thought I'd link to the most important new features, for future reference.

JDK7 Features

For us, developers, the most commonly used will be the ones made in Project Coin, I guess. Also take not of the features postponed to JDK 8 (at the bottom of the page)

Thursday, March 1, 2012

ADF 11g: Global date format

In ADF 11g, you can define a date format on many levels. On Entity Objects, View Objects, even on UI level in your JSF pages.

But wouldn't it be convenient to make 1 configuration and have all dates display the same? Well, this is possible. Just add this line of code to your trinidad-config.xml file (located in WEB-INF):


<formatting-locale>nl-BE</formatting-locale>


Of course, the locale you use determines the formatting. This particular example, nl-BE, will display all dates as dd/MM/yyyy.

ADF @ KnowledgeBlackBelt

Ever heard of KnowledgeBlackBelt? It used to be BlackBeltFactory. Doesn't sound familiar either? Perhaps JavaBlackBelt then? I'm sure that rings a bell to a lot of Java-oriented developers. Well, it's all the same site, it just has changed name (and layout) a few times over the years.

 In short, KnowledgeBlackBelt is a Java Learning & Certification community. Everyone can join and take free exams to gain grades. There are even courses (both free and paid) that handle certain topics and prepare you to take those exams. New users start out with a white belt, and eventually, after taking courses, exams and contributing to the community, they can become a Black Belt.

 I'm a contributor to the KnowledgeBlackBelt community. I have earned a brown belt over the years, and I'm the leader and moderator of the ADF Business Components exam. Check out the exam, and the entire concept that is KnowledgeBlackBelt. Learn, gain experience and get better at what you do.

ADF 11g: Get sequence in Groovy

A lot of people use sequences to generate an ID for their records. Since Oracle doesn't have an auto-increment, you need to manually get the next value and insert it into the ID field.


This can be done by triggers, but when you use Business Components, adding a one method and a single line of groovy code is enough. First, we need a method to get the next DB value:

  public Number seqNextVal(String seqName) {
 
    Number seqNextVal;
 
    if(seqName!=null && !seqName.equals("")) {
      SequenceImpl seq = new SequenceImpl(seqName, getDBTransaction());
      seqNextVal = seq.getSequenceNumber();
    }
    else {
      seqNextVal = new Number(0);
    }
 
    return seqNextVal;
  }


In the Id-attribute of your entity, you call this method by entering this expression in the value field:

adf.source.seqNextVal("SEQ_NAME")




Don't forget to check the Expression radio!

ADF 11g: Hide table column headers

Sometimes, you want to display a table, but hide the column headers. This can easily be done with ADF Skinning. First, we need to create a skin. This can be done by creating a trinidad-skins file in your META-INF folder. Since we only want to adjust our table in this simple example, we'll extend from the default Fusion desktop skin

<?xml version="1.0" encoding="UTF-8" ?>
<skins xmlns="http://myfaces.apache.org/trinidad/skin">
 <skin>
  <id>mySkin.desktop</id>
  <family>mySkin</family>
  <render-kit-id>org.apache.myfaces.trinidad.desktop</render-kit-id>
  <extends>fusion.desktop</extends>
  <style-sheet-name>/css/mySkin.css</style-sheet-name>
 </skin>
</skins>


As you can see, we refer to a css file there. Create it, and add this line to it:

.tableNoColumnHeaders af|column::column-header-cell {display: none}

Your skin has now been created, now we need to tell our application it has to use that skin. This is done in the trinidad-config.xml file, located in your WEB-INF folder. There, refer the skin-family to your own skin

<skin-family>mySkin</skin-family>

That's it. Your skin has been created. All that is left now is configure your table to use the style you just defined. Add following attribute to your <af:table> instance:

styleClass="tableNoColumnHeaders"