30 Dec 2017

Referring to ADF Faces component in EL expression

EL expressions are commonly used to specify attribute values of ADF Faces components on our page. It is interesting to know that we can use component keyword to refer to the component instance for which the EL expression is being evaluated. This is slightly similar to this in Java.

For example, in the following snippet the button's hint is evaluated as the button's text value and its visible attribute is going to be returned by a backing bean method accepting the component as a parameter:

<af:button text="#{theBean.buttonText}" id="b1"
 shortDesc="#{component.text}" visible="#{theBean.isVisible(component)}"/>

The backing bean method may look like this:
  public boolean isVisible(UIComponent button)
  {
    //Do something with the button
    ((RichButton) button).setIcon("images/awesomeIcon.jpg");


    //check button's attributes
    if (button. ...) 
      return true;
     else
      return false;

  }

This technique could be quite useful when it comes to rendering components inside some iterator (or list view or table, etc.) and we need to evaluate component's attribute value dynamically depending on the exact component instance.

That's it!


28 Dec 2017

Building Oracle ADF applications with Docker

Recently a good friend of mine was facing a regular problem with building an ADF application v.12.2.1.2 with the public Oracle Maven Repository. He asked me to check if it worked for me. Well... it didn't. So, there was some problem with the repository. In order to make the experiment clean and to avoid any impact on my working environment I decided to run the test in a docker container. And even though I could not help my friend (it simply didn't work throwing some dependency exception), as the result of this check I got a reusable docker image which serves as a preconfigured building machine for ADF applications (for v. 12.2.1.3 the Oracle Maven Repository worked fine at that moment).

This is what I did:

1. Pull and run an ubuntu Docker image

$: docker run -it --name adfbuilder ubuntu


2. Install Java in the adfbuilder container

apt-get install software-properties-common python-software-properties
add-apt-repository ppa:webupd8team/java
apt-get update
apt-get install oracle-java8-installer

3. Install Maven in the adfbuilder container

Just download maven binaries and unzip them in some folder and copy into the container:

docker cp ~/Downloads/apache-maven-3.5.2 adfbuilder:/opt/apache-maven-3.5.2

Update PATH environment variable in the container

export PATH=$PATH:/opt/apache-maven-3.5.2/bin

Having done that, the mvn should be available. Run it in the container and it will create a hidden .m2 folder in the user's home.

4. Configure Maven in the adfbuilder container to work with Oracle Maven Repository

Just put in the hidden .m2 folder 

 docker cp settings.xml adfbuilder:/root/.m2/settings.xml

settings.xml file with the following content:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0                       https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <servers>
    <server>
      <id>maven.oracle.com</id>
      <username>eugene.fedorenko@flexagon.com</username>
      <password><MY_PASSWORD></password>
      <configuration>
        <basicAuthScope>
          <host>ANY</host>
          <port>ANY</port>
          <realm>OAM 11g</realm>
        </basicAuthScope>
        <httpConfiguration>
          <all>
            <params>
              <property>
                <name>http.protocol.allow-circular-redirects</name>
                <value>%b,true</value>
              </property>
            </params>
          </all>
        </httpConfiguration>
      </configuration>
    </server>
  </servers>
  <profiles>
    <profile>
      <id>main</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
          <id>maven.oracle.com</id>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <url>https://maven.oracle.com</url>
          <layout>default</layout>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>maven.oracle.com</id>
          <url>https://maven.oracle.com</url>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
</settings>
Basically, this is enough to compile a Maven-configured ADF application in the container. We need to make sure that there is an access to the source code of our application from the container. This can be done either by mapping a source folder to be visible from the container or just by coping it into the container.

docker cp /mywork/MySampleApp adfbuilder:/opt/MySampleApp

Having done that, we can run the following command to get the application compiled:

docker exec adfbuilder mvn -f /opt/MySampleApp/pom.xml compile

5. Copy JDeveloper  binaries into the container
As we want to go beyond this point and be able not only to compile, but to produce deployable artifacts (ears, jars, etc.), we will need to put JDeveloper  binaries into the container (basically, maven will need ojdeploy).  I have just copied  Oracle_Home folder from my Mac to the container:

docker cp /My_Oracle_Home adfbuilder:/opt/Oracle_Home

So, now I am able to build a ear for my application in the container:

docker exec adfbuilder mvn  -f /opt/MySampleApp/pom.xml package -DoracleHome=/opt/Oracle_Home

For the first run it may ask you to provide you the path to your JDK

[INFO] Type the full pathname of a JDK installation (or Ctrl-C to quit), the path will be stored in /root/.jdeveloper/12.2.1.3.0/product.conf
/usr/lib/jvm/java-8-oracle

6. Commit changes to the container
The final thing we need to do is to commit changes to the container:

docker commit adfbuilder efedorenko/adfbuilder

This will create a new ubuntu image containing all changes that we applied. We can easily run that image wherever we want across our infrastructure and use it as a building machine for ADF applications. The beauty of it is that we can run it in a cloud like Docker Cloud (backed by AWS, Microsoft Azure, Digital Ocean, etc.) or Oracle Container Cloud Services or whatever you prefer. With this approach servers in the cloud build your application for you which in general is a quite resource-consuming job.

Thant's it!