Friday, March 27, 2015

Custom fonts in ADF 11g

There are beautiful fonts you may want to use in your web applications. In this post I'm going to show you how you can use custom fonts such as Google Fonts in your ADF 11g Applications. For ADF 12c Applications, you can find more instructions here.

What you need

For JDeveloper 11gR1 you should download the ADF Skin Editor (download the latest release) since this version doesn't come with that tool integrated to the IDE. On the other hand, 11gR2 has the ADF Skin Editor tool integrated to JDeveloper.

As a best practice you should create your own skin based on a skin provided by Oracle. That way, whenever you want to change the font of your entire application, there is only one place to make the change: the custom skin. This post is based on this best practice, so make sure you understand how to work with ADF skins.

This is the font family we are going to use in this post. It's called Indie Flower

Since ADF 11g skins make use of CSS2, the process of using custom fonts is not as easier as in 12c, but we have a workaround for that, just make sure you use a custom skin and a page template on your application.


Custom fonts in ADF 11gR1 and 11gR2
If you are using 11gR1, create the skin application using the skin editor. Steps are as follows (Remember, if you are using 11gR2 you can create the skin from within JDeveloper):
Click on new application... Set the name and folder...
Set the skin project name and the target application release that you want to skin:



Then, create a new ADF Skin File (right click on project and select Create new ADF Skin File)



Extend whichever Oracle skin you want, JDeveloper will suggest you one if you like. When the Skin Editor opens, go to Selectors and expand the Global Selector Aliases node and then Font, there you can see the class ADFDefaultFontFamily which is where we need to make the change in order to set the new font family for our entire ADF Application. Go to the Properties Inspector and make the change in the Font Family property:






That's it, we have defined that all the components in an ADF application that uses this skin will use the custom font (except for those defined with a specific inlineStyle). However, if you notice we haven't told the skin file where the custom font is, that's because skins in 11g use CSS2 and so we can't define nor import the font in the skin file, if we do, it will get removed at runtime. The downside of this is that we can't use the skin editor to preview the font family change.

If you are using ADF 11gR1, deploy the custom skin as an adfLib (right click on project -> deploy...) and import it into your ADF application.
If you are using ADF 11gR2, this is not necessary since you can create the custom skin from within your project in JDeveloper.
Anyway, remember to change the {WEB-INF}/trinidad-config.xml file to make use of your custom skin:

...
  <skin-family>custom-skin</skin-family>
  <skin-version>default</skin-version>
...


The second part of the solution requires the use of Page templates, if you are not using page templates in your application, you will have to modify every single page where you want to use the custom font. The code you add to your page template or to your single page is the same:

<af:resource type="css" source="http://fonts.googleapis.com/css?family=Indie+Flower"/>


Here, we are adding a CSS resource where the custom font is defined. You may wonder where have the URL come from, well if you go to the Indie Flower font quick use, you will notice the URL is there.

Wondering where to place the above code? If you are using page templates, place it right after the jsp:root tag, on the other hand, if you are using single pages, place it inside the document tag.

Now, if you run an ADF application that makes use of your custom skin, all your components will be using the same font-family:


Before using custom fonts

After using custom fonts



That's it, hopefully you now will be able to modernize your ADF 11g applications using new custom fonts.

see ya!

Saturday, March 21, 2015

Custom fonts in ADF 12c

There are beautiful fonts you may want to use in your web applications. In this post I'm going to show you how you can use custom fonts such as Google Fonts in your ADF 12c Applications. For ADF 11g Applications, you can find more instructions here.

What you need

As a best practice you should create your own skin based on a skin provided by Oracle. That way, whenever you want to change the font of your entire application, there is only one place to make the change: the custom skin. This post is based on this best practice, so make sure you understand how to work with ADF skins.

This is the font family we are going to use in this post. It's called Indie Flower

Since ADF 12c makes use of CSS3, the process of using custom fonts is simpler than it was in 11g.

Custom fonts in ADF 12c
Create your skin if you have not created one yet. In JDeveloper 12c you can use the integrated ADF Skin Editor tool as follows:




Extend whichever Oracle skin you want, JDeveloper will suggest you one if you like. When the Skin Editor opens, go to Selectors and expand the Global Selector Aliases node and then Font, there you can see the class ADFDefaultFontFamily which is where we need to make the change in order to set the new font family for our entire ADF 12c Application. Go to the Properties Inspector and make the change in the Font Family property:






Then, open the Source editor (next tab after Selectors) because we need to define the custom font. The following shows you an excerpt of the Skin CSS where we have defined the font and overridden the font-family property of the  ADFDefaultFontFamily class

...

@font-face {
  font-family: 'Indie Flower';
  font-style: normal;
  font-weight: 400;
  src: local('Indie Flower'), local('IndieFlower'), url(http://fonts.gstatic.com/s/indieflower/v7/10JVD_humAd5zP2yrFqw6ugdm0LZdjqr5-oayXSOefg.woff2) format('woff2'), url(http://fonts.gstatic.com/s/indieflower/v7/10JVD_humAd5zP2yrFqw6nhCUOGz7vYGh680lGh-uXM.woff) format('woff');
}

.AFDefaultFontFamily:alias {
    font-family: 'Indie Flower', cursive;
}

...


You may wonder where have the @font-face instruction come from, well if you go to the Indie Flower font quick use, you will notice there is the following link:

http://fonts.googleapis.com/css?family=Indie+Flower

If you open it, you will find the @font-face definition that you need to use in your Skin CSS. In the same quick use link you will find several ways to use the font: using a link, using an @import instruction and even suing JavaScript. However, only copying the @font-face instruction in the Skin CSS worked for me.

ADF Skin Editor 12c comes with a handy option where you can launch your browser and check the changes you have made to the skin without launching Weblogic or your ADF application:



Let's see how this works before and after changing the font-family:

Before using custom fonts
After using custom fonts


Now, if you run an ADF 12c application that makes use of your custom skin, all your components will be using the same font-family:


Before using custom fonts

After using custom fonts



You should be aware that if you have components that make use of the inlineStyle property or use any other custom class, then those components won't use the default font-family defined in the skin.

That's it, hopefully you now will be able to modernize your ADF 12c applications using new custom fonts.

see ya!

Should I commit .adfc_diagram files?

Wondering whether you should commit *.adfc_diagram files?
You should know that JDeveloper saves the position in the diagram of each component in these files, so if your diagram looks like this:



And if you don't commit these files, next time you checkout/clone from your version control system, it may look like the following, since JDeveloper will create a new file with default positions:



Each task flow has its own file, and the name for these files follows this pattern:

{TASK_FLOW_ID}.adfc_diagram

Where {TASK_FLOW_ID} is the task flow id you defined for the task flow when you created it. Now, if you want to know where is JDeveloper saving these files, you can go to Project Properties -> Project Source Paths -> Modelers:



Further more, if you want to know/change the directory where JDeveloper saves theses files inside your project, go to Application -> Default Project Properties -> Project Source Paths -> Modelers:



see ya!

Tuesday, January 6, 2015

Book Review: Mastering JavaServer Faces 2.2

Book cover from
http://www.packtpub.com
Java EE 7 is the latest version of the Java Enterprise platform. Lots of new features and three objectives: Developer productivity, HTML5 and Enterprise Demands.

In this post, I'll be reviewing the book "Mastering JavaServer Faces 2.2" written by Anghel Leonard and published by PACKT. As many others Packt titles, the chapters are easy to read, they follow a tutorial approach and a summary at the end.

I think this book is good for new and experienced Java EE developers. If you are a beginner, this book will teach you what you need to know about JSF to start your next project.
On the other hand, if you are an experienced Java EE developer you will find this book very easy to read. Just focus on the new features of the specification and you'll get updated to the latest version of JSF in a fast paced.

What I liked about the book:

  • Easy to read.
  • As an experienced Java EE developer it was easy to focus just on the new features.
  • Sample code is available to be downloaded from Packt's website and it is well organized, so I can download exactly the code of the chapter I'm reading.
  • Teaches you both: Annotations and XML configurations. You never know when you need to open those legacy XML files...
  • Chapter 7 (JSF and AJAX) and Chapter 8 (JSF and HTML5) are the ones I liked the most since these topics are a must in today's web applications.


For more information go to:
https://www.packtpub.com/application-development/mastering-javaserver-faces-22

See ya!

Thursday, December 18, 2014

USD $5 Bonanza from Pack Publishing is Back!

Just a quick post with a great offer from Packt Publishing:

From December 18th 2014 until January 6th 2014, you can get any eBook or Video from Packt for just USD $5!

More info: http://bit.ly/13fDngD

This is a great offer to start the new year (2014) with some books to read. Go get yours!




Friday, October 3, 2014

JavaOne 2014 - Tuesday

Hi all, here are my notes of the sessions I attended on Tuesday at JavaOne.

Where is my Memory
Important session about managing memory on your JVM. The speaker introduced us to the different memory regions on the JVM and gave us good advices about how to find memory leaks on your JVM.

Some of the tips we got during the session:

The less options you have at your startup script, the better!

if you want to know default options for your JVM use the following:
java -XX:+UnlockDiagnosticVMOptions -XX:+PrintFlagsFinal -version

Of course you always want to go with non-default sizes, but you should go with small increments of memory for your -Xmx and -XX:MaxPermSize options

An Important difference between Java 8 and prior versions of Java is that Java 8 got almost all the naked memory available and if you want to tune it, then you should reduce it

Developers do not think about memory, they don't destroy objects or freed memory because of the Garbage Collector, which is a subsystem of the JVM for reclaiming "unused" memory

There are some objects that are always alive and wont be collected by the garbage collector, which are called GC Roots

  • System classes
  • JNI references
  • Running Threads
  • Local variables or parameters
  • Native stack
  • Used monitors
  • And some others

This is how the garbage collector works:

  • Mark all GC Root as reachable
  • Mark all objects referenced from reachable object as reachable too
  • Repeat until all reachable objects are found
  • Everything else is garbage 

So, what is a Memory Leak?
Reachable objects that will never be used by your application and/or the repetitive creation of such objects. Some examples of memory leaks are:

  • Caches without look-ups and eviction
  • String.substring -> Prior to Java SE 7
  • Immortal threads
  • Unclosed IO streams

The symptoms of your memory leak are either OutOfMemoryError or the application runs too slow due to the excessive GC, but be careful since there may be false positives due to:

  • Too high allocation size 
  • Cache with the wrong size - Check the size of your cache
  • Trying to load too much data at onces - You can use lazy loading
  • Fat data structures - Inneficient datastructures to hold your data

Memory monitoring tools

  • VisualVM/Java Mission Control
  • jStat
  • GC logs - Use the following options -XX:+PrintGCDetails -XX:PrintGCTimeStamps -Xloggc:file.log -XX:+UseGCLogFileRotation -XX:Number at your startup script and then use GC log analyzers such as Fasterj or GCViewer

So you have a memory leak, then try this as first step

  • Reduce memory usage
  • Tune GC
  • Increase Xmx/PermGen

If it doesn't work, then you should try more advanced techniques such as Memory (Heap) dump to find out what consumes memory. Memory dump is a binary representation of objects graph written to a file. Have in mind that it is not an accurate representation of the memory but is good enough to find memory leaks.

In order to get a memory dump you can use one of the following:

  • jmap -dump:format=b,file=heap.hprof
  • Add this options to your startup script:
    -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./java_pid<pid>.hprof

The tool used to analyze the Memory Dump is Eclipse Memory Analyzer and you should look for objects with the biggest retained size.

A final word from the speaker:
Do not use Profilers to find Memory Leaks!

More information about solving Memory leak can be found at:
https://plumbr.eu/blog/solving-outofmemoryerror-story-of-a-developer


Hackergarten
Went to the Hackergarten again and during the time I was there I met Werner Keil one of the spec leads of JSR 363: Units of Measurement API, who walked me through the status of the JSR and point me to several documentation sources. This JSR is also available to adopt through the Adopt a JSR program.




RIA Technologies and Framework Panel
There was this excellent panel of experts in the RIA topic. They discussed about the state of art regarding to RIA technologies.

Native or HTML5 ?
There were a lot of opinions here, but at the end, most have agreed that in house development for administrative purposes should go HTML 5. But if you really need to get the best of the platform go native even if you have to do it for three different platforms. The audience were asked if we were doing native development for our mobile projects, just a few raised their hands.
An advice to promote code reuse is to develop your backend to return JSON so your native apps or HTML 5 apps con consume it.

Is JavaFX the future of client side Java?
Some have said Swing is gone, JavaFX is the present of client side Java, but, the audience were asked whether they were building desktop applications and many raised their hands. Then they were asked whether they were using JavaFx or Swing... and most of them are using Swing and are not planning to move to JavaFx... So the question remains and is not clear whether JavaFx is replacing or not Swing.

Last question was about what panelist are excited about for the next years?
Swing + HTML 5 - Andres Almiray
No Wrappers for HTML 5 apps - Max Katz
iOS SwiftKevin Nilson
Curious about what will happen on the UI market - Gerrit Grunwald
What new tools will come up for UI - Sven Reimers


Delivering Oracle ADF Projects: Modern Techniques
This session was really interesting because it was about using modern development techniques on the world of ADF. We saw how we can use plugins for quality of code in ADF. Also explored how testing ADF applications can be automatized by using the Oracle Application Testing Suite. Last but not least, we saw how we can use Maven with ADF. I am excited about this new feature since I've wanted to create a continuous integration environment with ADF for a while. I think I found what my next talk about ADF is going to be...


ODTUG Oracle Developers Meetup
Had the chance to meet ADF celebrities and other ADF developers on the Oracle Developers meetup, an event organized by ODTUG. I could see how popular ADF is becoming, more developers are now working with this technology and are excited about the new releases.




Oracle ADF Enterprise Architects Birds­of­a­Feather Meeting
This session was about architectural challenges that we face when developing with ADF. The session was more Q&A oriented. Some of the participants were Sten Vesterli, Chris Muir and Frank Nimphius. So imagine you, with some ADF questions and having these ADF masters in front of you to help you find your path... that's priceless.


At night we went to the Red Hat party, where we could hangout with Arun Gupta, Kevin Nilson and Dario Laverde. Had some drinks and food and enjoyed the end of day 3 at JavaOne! What a great day.





see ya!

Wednesday, October 1, 2014

JavaOne 2014 - Monday

Hello there, this was day two of JavaOne 2014, it was a full day of conferences, tried to attend as many as I could and with a wide range of topics:

How to build enterprise mobile apps that integrate with your Java EE backend
The talk was about Hybrid Apps and how to connect them to your Java EE app. A hybrid app is written with web technologies but runs as native app. 

The speaker explained how Apache Cordova wraps the html app, lets developers create JS libraries to access native features such as the camera and packs the app as an Android or iOS native app.
Regarding to the IDE, he showed how you can use Eclipse with JBoss Tools plugins and Eclipse thym plugin in order to create a hybrid mobile app. From Eclipse you can write your html files and test them on the Cordova browser which is integrated to Eclipse or you can use an emulator called Genymotion which is an Android emulator. One good thing about the emulator is that you can connect your Chrome developer tools to it.
Another nice feature is called LiveReload Server which lets you change your code and watch the changes immediately on the test browser (does not work with the emulator)

The speaker talked about how responsive frameworks such as bootstrap or heavy frameworks such as jquery mobile are not good enough for today's mobile apps. He introduced us to the ionic framework and talked about some of its pros: mobile only, big community and is integrated with Angular JS

Then we saw how JBoss Forge can help us in order to create our java classes and rest end points very fast and easy. The rest end points can be tested from Google Chrome using the Postman plugin. He also used Forge  to create the ionic application with a few commands on the console.

Regarding to Push notifications, we saw how the Unified PushServer, which is an Eclipse plugin it's a server to be deployed and it comes with Clients SDKs (ios, Android and Cordova), can help us on implement Push notifications for several platforms such as iOS, Android, Amazon, Firefox, etc. Without having to code them ourselves.

Here are the tools used during the presentation in order to develop the hybrid application:
Genymotion -Android emulator
ionic - Mobile only HTML 5 framework
Angular JS - HTML 5 web framework
JBoss Forge - Rapid Application Development tool for Maven and Java EE
Postman - Plugin for Google Chrome to test your rest en points
AeroGear Push - Push Notifications


Hackergarten
There was a space at the JavaOne exhibition hall where attendees could contribute to open source projects, meet members of the JCP and hangout with other developers. There were different topics each day. On Monday, for example, during the time I was there I met Anatole Tresch the spec lead of JSR 354 - Currency and Money. A very nice person, who kindly explained me some parts of the API and how we can participate through the Adopt a JSR program.





Thinking in Functional Style
This is one session I could not attend last year, so this time I arrived early in order to make it inside the room. Venkat Subramaniam is by far one of the best speakers I have ever seen. He introduced us to functional programming with simple examples and engaged the audience with such simple stories, jokes and easy vocabulary. When he starts talking, he doesn't stop until the session is over. Highly recommend to attend to his sessions. Here are some topics about functional programming that he talked about:

  • Assignment-less programming
  • Immutable state -> Less error prone
  • Functions with no side-effect
  • Declarative - The what, transform data, pure, pass functions as parameters, functional composition
  • Function composition - You can chain functions
  • Lazy evaluations - Is good since not all evaluations are applied
  • Immutability and pure functions make functional programming


You can download the topics list and code examples from:
Thinking in functional style


JCP anniversary
At night, we were invited to the 15th anniversary of the JCP. Special thanks to Heather Vancura for such a great party at the 46th floor of the Hilton Union Square hotel. Nice view of San Francisco, food and beverage, entertainment was provided by the NullPointers, a band of Java Geeks who showed their passion for music.





Was a great day, looking forward for more fun at JavaOne.

See ya!

Tuesday, September 30, 2014

JavaOne 2014 - Sunday

I had my presentation on Sunday, talked about developing web apps using ADF Essentials + MySQL + Glassfish server.

The room was full! and I'm glad I shared my experiences using this technology. I have to improve my timings, though. You can download my slides here.

At the end, few questions and the relief of having done a good job.


The JavaOne Strategy and Technical keynote started really good with the following video:



However, I have to say that the rest of the keynote was not what I was expecting. And I'm not saying that because the Demo car didn't work at first, but the way how the keynote ended, just when Brian Goetz, the Java Language Architect!! Was talking about lambdas and the presentation was getting better... He was literally kicked off stage.

In the afternoon attended a few more sessions about ADF. At evening, went to the Glassfish appreciation event, which was held at the Thirsty Bear, good food, free beverages, yeii!!


see ya!

JavaOne 2014 - Saturday

So, for those of you who don't know this, JavaOne actually starts on Saturday. There are some activities before the actual starting day that you don't want to miss.

For example, there is the Geek Bike Ride, which is really fun, it is organized by +Kevin Nilson, a well known java community leader. We started at fisherman's and went across the Golden Gate bridge heading to Sausalito where we enjoyed a good meal after the workout. Then we took the ferry back to San Francisco and enjoyed an amazing view of the bay.

Some pictures of the bike riding:




Also, there was an event called Devoxx4Kids, where about 150 kids spent the whole day learning about programming. They used scratch, arduinos, and legos. Some of the Java community members were volunteers and helped during the sessions.

Some pictures about Devoxx4Kids:




If you are planning to attend JavaOne 2015, make plans to arrive on Friday so you can enjoy these pre-conference events. 

see ya!

Tuesday, August 26, 2014

CLOJUG AUG 2014 - Java SE 8 - Java IoT - Adopt a JSR

Hello all! This is a small update about what we did at the Cali (CLO) Java User Group - CLOJUG during August 2014.

This month we had an extra meeting with students at Universidad Javeriana where we talked about the new features of Java SE 8: Date and Time API, Lambda expressions and Streams API. Most of the students had zero or little experience with Java but they were really interested about these new features. The presentation about Java SE 8 can be downloaded from here (in spanish).

We run our regular meeting on 23-AUG-2014 at Universidad Icesi. This meeting was about Java and IoT. One of our members, +Sandro Hdo. Preciado Castro gave us a really great talk about this topic. We all enjoyed watching him with his electronic "toys" and learning from his experience with Java, Raspberry Pi and other devices.

We also talked about Adopt a JSR, we are about to enter the program and, as a start, we'd like to Adopt JSRs from Java SE 9 such as Money and Currency API (JSR 354) and Units of Measurement API (JSR 363). We'll let you know when we have entered the program and we've started to work on these two APIs.

Here are some pictures of this event:






Stay tuned for our events and if you live in Cali-Colombia, come to our meetings and become a member of our great community! http://www.clojug.org/

see ya!