Using Conditional Breakpoints

Conditional breakpoints are a great way to reduce debugging time and one of those features you might not even have known existed. This article will cover how to use them in 3 different ide’s including NetBeans, Eclipse and JDeveloper.

Have you ever tried to debug a problem that only occurs somewhere in a list of 100 objects? It can be a bit of a hassle.

You could put in a breakpoint and hit continue each time that breakpoint is hit until you find the problem object. This is acceptable the first time, but often the first time isn’t going to cut it.

You could put an if statement in your code to check for the condition that is causing the problem, but then you need to remember to remove that if statement after you fix the problem. Often my if statements in the past would have looked like this:

i f (problem.exists()) {

System.out.println(”This is the problem.”);

}

And I’d set a breakpoint on the System.out.println line.

A much better approach is to make use of conditional breakpoints available in most modern IDE’s.

NetBeans Breakpoint Editor

In NetBeans, create a breakpoint, the right click on the little pink square that signifies the break. Click on “Customize”. When the customize dialog comes up, check “Condition” and fill in the condition. Above is an example of this dialog in NetBeans.

Eclipse Breakpoint Properties

To accomplish the same thing in Eclipse, create your breakpoint, then right-click on the little blue dot signifying the breakpoint and choose “Breakpoint Properties”. In the Properties window, check “Enable Condition” and then fill in your condition or conditions in the box provided. An example is shown above.

Finally, to accomplish the same in JDeveloper (TP4, anyway), set your breakpoint, right click on the little red circle that appears. Then click on “Edit Breakpoint” and in the dialog that pops up, move to the “Conditions” tab. You can set your conditions there as shown in the picture above.

So now that you know, from now on, no more useless breakpoints!

And if you’ve still been debugging using System.out’s, I’m sorry I wasted your time. I’m sure Vi is just sitting there flashing it’s cursor at you waiting for you to save those changes.

Share/Save/Bookmark

Create and Deploy a JavaFX WebStart Application

I realized when I updated my FlashCard JFX game that I could not remember what I actually had to do in order to create a deployable Java WebStart application. So that I always had a simple reference to refer to, I’m posting it here. Hopefully this will help someone else.

Basically, a JavaFX application is typically deployed through Java Web Start, so I think most of these instructions will apply to any Java Web Start application. Steps 1 through9 are from the help in NetBeans itself. The part about signing the jars is from Kirill Grouchnikov’s blog.

1. Use NetBeans - there are other ways, but this is a requirement to follow my way.

2. Install the JavaFX plugin.

3. After running your project locally and making sure it works and all the dependencies are there, right click on the project and choose “Properties” from the menu.

4. Choose Categories: Application -> WebStart.

5. Check “Enable WebStart”.

6. Fill in the codebase to the directory where you will copy up the dist folder to on your web server. For me it is “/downloads/flashcardjfx/dist”

7. Choose “Run” from the Properties list.

8. Name the configuration and check “Run with Java Web Start”.

9. Clean and build your project.

10. Cd to the dist directory of your Java FX project.

11. Run keytool using something similar to this:

keytool -genkey -keystore javahair.keys -alias / -validity 365

12. Sign your main jar by running something similar to this:

jarsigner -keystore javahair.keys -storepass ***** FlashcardJFX.jar /

13. Cd to the lib directory in your dist and sign all the jars there like so:

jarsigner -keystore ..\javahair.keys -storepass ***** javafxrt.jar /

14. FTP all the contents of your dist directory to your webserver to the codebase directory you specified in step 6.

Now link to the launch.jnlp file in that directory and you should be good to go.

The older articles in this how-to can be found here:

Learning JavaFX

JavaFX Example - FlashCard Game

JavaFX FlashCard Source Code and Web Start Link

Adding Sound to the FlashCard JavaFX Game

Share/Save/Bookmark

Vote for my Oracle Open World Session

The talk I presented at ODTUG this year went over very well with the people who attended, but unfortunately, there were not all that many in attendance.  Since I missed the deadline for the normal submissions to Oracle Open World this year, I submitted by talk to Oracle Mix’s session submission area.  As one person put it, Oracle Mix is pretty much facebook for people working with Oracle technologies.

Anyway, you can vote to see my session at Open World by clicking here.  I promise you that my presentation is not a vendor presentation, I don’t talk at all about Vgo Software or the tool(s) that we make that make the process of modernizing forms easier.  What I do talk about is how ADF 11g allows you to rewrite Oracle Forms applications in a web environment and some of the pitfalls you will run into when you try to do this.

The presentation also includes a demonstration of creating a Master-Detail page in ADF 11g, much like some of my previous blog-posts.  It is after all, one of the cornerstones of an Oracle Forms application.

Share/Save/Bookmark

Adding Sound to the FlashCard JavaFX Game

I finally had a small amount of time to look into adding sound to my flashcard java fx example, something I have wanted to do for a while now. When I finally got the time, I realized that it isn’t so difficult since most of the hard work has already been done.

The first step in adding any major functionality to an application like this is searching Google to see if anyone has done this before. I found an example of using MP3’s in a JavaFX application, but I didn’t like it. I didn’t like it because the article seems to point to using this embeddedmp3 library which I did not see the source for. The library in the article, however, is based on JLayer, and JLayer is what I used for my FlashCard game.

After including the 1.0 version of JLayer into my project, I created a utility class to be used for playing the np3 files. I called it Mp3.java.

What I wanted was a class that would hold a reference to the mp3 to be played for a particular card, so I decided that it would have a private attribute to hold that location. My first mistake was forgetting the type of application I was dealing with and I used a String pointing to the actual file to hold the location. I looked at what I was doing for images and just did the same sort of thing.

For the images I was storing them inside the jar itself in a package “flashcardjfx.img”, so for the mp3’s I put them in a package called “flashcardjfx.sounds”. The constructor for my Mp3 class (which at this point, is not really a util anymore, but once I put it in that package I was too lazy to move it) takes a String that is the location. I saw that the JLayer Player needs an InputStream so I created a FileInputStream on that location and was storing that.

When I tried to test my application, I kept getting an error that the file could not be found. I think when I moved the mp3’s to a c:\sounds directory, they were found, but that wasn’t going to help me much when I deployed. So, what to do? Well, after playing around with it for a little while, it dawned on me, that the String I was passing to the Image was not for a file, but a URL. Of course, right? I am dealing with JavaFX here and an application running via Web Start. So… once I changed my reference from a File to a URL, bingo!, it all started coming together.

My MP3 class is shown here, it is also now included in the down-loadable source code.

public class Mp3 {
    private URL url = null;

    public Mp3(String url) {
        try {
            this.url = new URL(url);

        } catch (IOException ex) {
            Logger.getLogger(Mp3.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void play() throws FileNotFoundException, JavaLayerException {
        try {
            //Make sure to open and close the player each time!
            Player mp3Player = new Player(url.openStream());
            mp3Player.play();
            mp3Player.close();
        } catch (IOException ex) {
            Logger.getLogger(Mp3.class.getName()).log(Level.SEVERE, null, ex);
        }
    };  

}

Simple, right? Not much to it. To use it in my FlashCard JavaFX class I had to add a private variable to hold the “Mp3″.

private attribute mp3: Mp3;

Then, at the end of the flip() operationI added this line:

mp3.play();

And that is about it to get it to play.

For the constructor, I added a String to the location of the mp3 and I just set my mp3 variable to a new Mp3 instance based on that location:

   operation FlashCard.FlashCard(aWord:String, anImage:String, aMp3:String) {
      mp3 = new Mp3(aMp3);
      word = new Word(aWord);
      cardImage = new CardImage(anImage);
   }

Now to create a new flashcard, I just pass in the mp3 location as well as the word and the image location.

insert new FlashCard("cat", "{__DIR__}/img/cat.png", "{__DIR__}/sounds/cat.mp3") into flashcards;

It has dawned on me that if I keep the naming structure the same, I only need to pass in the word, but that may be too much menial cleanup work for something that is just an example.

So the new source is available where the old source was: here.

The application itself can be launched by clicking here. You can thank my youngest daughter, Cassie and myself for the voicework. I will probably update with a version that does not use my voice, as either her’s or her sister’s is much better.

The older articles can be found here:

Learning JavaFX

JavaFX Example - FlashCard Game

JavaFX FlashCard Source Code and Web Start Link

I’ll be posting an article about deploying since I couldn’t remember how to do it this time either.

Share/Save/Bookmark

ODTUG - Final Day

Today was a short day, for manning the booth anyway. We didn’t have anything to give away this year so it made the close of the booth somewhat less exciting. I didn’t actually get to see any sessions today, but I did manage to talk to many people that are trying to decide what to do with their old Oracle Forms applications.

I told them what I always tell ‘em. Upgrade your forms for the most part, unless you have a compelling reason not to do so. Converting to ADF or Java is going to be time consuming and expensive, even when you use a tool like Evo.

I got to find out what the JHeadstart gang have been up to. I even managed to catch up with Wilfred and Grant today, so it hasn’t been a total loss.

I should have taken some pictures of our booth with my phone but I did not. Stacey, the marketing associate with us got some good pictures of it on her camera. I’m sure she’ll have those pictures up on the site sometime soon.

Tonight is the big Fat Tuesday on Wednesday bash, so that should be a fun end to trip for us. For Andrej, being an Oracle Ace Director, he gets to spend a few extra days exploring New Orleans, not a bad deal.

Hopefully our presentations will be up on the ODTUG site soon so that you can download them and take a look.

Now that I’m coming back from the conference, the next blog posts should have a little more meat to them. I think I’m about overdue for something technical.

One last thing before I forget, a picture of Andrejus during his presentation!

Share/Save/Bookmark

ODTUG - Day 3

So Day 2 came and went. I spent a lot of time in the booth on Day 2. I managed to see a couple presentations. One was by Peter Koletzke, a presentation about migrating a Forms 3 character-based application to a Java EE application. I had thought it was going to be about other Java frameworks, but as it turned out it was actually about using JDeveloper and ADF. Pretty high-level, but it was interesting to see their approach which really wasn’t too different from ours.

More important, to me, was Andrejus Baranovski’s presentation, “Development with Oracle JDeveloper/ADF 11g Reusing 10g Best Practices”. It was well attended and well received and that was a good thing.

I did manage to see the Welcome and Conference Awards.  I was happy to see Lynn Munsinger win the Oracle Contributor of the Year award, she deserves it.

Today, I’ve spent most of my time in our booth again, attending no other presentations besides my own.  I am happy to say that it was attended fairly well and it seemed to go over pretty well.  I can’t wait to see the feedback as I’m sure I could improve.

As compared to last year’s conference there seem to be many more talks on using Java (mostly in the context of ADF, but not always), so I like to see that.  Unfortunately, I need to spend a lot of time manning the booth and don’t necessarily get the chance to see those presentations.

We have a little more time to spend in the booth today before we find a nice New Orlean’s restaurant to go to and get some good local food.  I think if we can find Emeril’s restaurant, we’ll be there.

Tomorrow is essentially the last day of the conference, ending with a “Fat Tuesday on Wednesday” party.  I’ll let you know how that turned out on Thursday.

Share/Save/Bookmark

ODTUG - Day 1

This is officially the first day of ODTUG, the opening keynote by Tom Kyte took place at 7.  Right now the Welcome Reception is just about ending.  In a nice addition to the conference they had an open “Jam Session” with a small stage set up and some instruments available.  The talent here is actually quite good and I just got done listening to a great version of “Johnny B Good”.

I wasn’t going to post too many details about the conference but I thought the fact that just like this blog the conference was blending technology and music was too much of a coincidence to let it pass by.

So far we’re off to good start.

Share/Save/Bookmark

The Lemonheads

As you know if you pay any attention to my music posts, I am a pretty big fan of punk rock. I’m not even ashamed to admit that I indulge myself in the genre sometimes known as pop-punk. One of the bands that originally turned me on to poop-punk was The Lemonheads. I had been listening to punk rock for a while, bands like The Clash, Sex Pistols, Ramones, etc, and I liked it, but there was something about The Lemonheads that I really enjoyed.

The Lemonheads - Hate Your Friends

Now I know there were other pop-punk bands out there at the time, but the Lemonads with Evan Dando were one of the first bands that I listened to where the music was definitely punk rock, but it was catchy (so far the Ramones), and the lead singer sometimes actually sang the lyrics (Sorry, Joey).

I’m not talking about their later mostly pop albums, I am mostly referring to “Hate Your Friends”, “Creator”, and even “Lick.” The album “Lick”, by the way, contains a great cover of Lukas by Susanne Vega.

At this period in their history, vocal duties were shared by Evan Dando and Ben Deilly. Both of them actually do a good job with the band, but I prefer Evan. If you are as old as I am you might even remember Evan Dando was once on the cover of People magazine.

If you are looking for some decent late 80’s or early 90’s pop-punk, check these guys out. They might be more “punk” than “pop”, especially back then, but they are certainly worth a listen.

Do you think I could open my talk on ADF 11g by playing their cover of “Amazing Grace”?

Share/Save/Bookmark

ADF 11g Master-Detail Part 2

This tutorial explains how to add some useful functionality to the Master-detail page we created in the last tutorial. The first thing you will need to do in order to follow along is to follow the steps in that post.

Today we will add some functionality to allow the user to add, edit, and delete employee records from the detail table.

1. Adding Read-Only Views

1a. Before we get started with the view, let’s add a couple of ADF Business Components to our Model layer. We are going to want to create a couple of drop down lists, so to do that, we need a Read Only view that can populate the drop down list.

1b. Right-click the Model project, choose New, then choose ADF Business Components from Tables.

1c. Do not choose to create any Entity objects since we have the two we already need from last time. Same deal with Updateable Views, so click Next on both of those screens.View of ADF LOV

1d.On Step 3 of the “Create Business Components from Tables” wizard, select Employees and Locations and choose to create Read-Only Views for those two tables. Rename the new Employee View to ManagerView.

2. Adding “List of Values”

2a. Open the EmployeView in the Model project. Click on the ManagerId attribute.

2b. Underneath, on the toolbar that says “List of Value” click the green plus-sign to open the List of Values wizard. Click the green plus and choose the ManagerView from the left-hand list of available view and move it to the right-side list of View Accessors. Click OK.

2c. In the top pane, open the ManagerView and click on EmployeeId, then click the green plus underneath the “List Data Source” pane. JDeveloper should add ManagerId under View Attribute and EmployeeId under List Attribute which means it is linking the managerid in the EmployeeView to the EmployeeId in the ManagerView.

2d. Click on the UI Hints tab and choose “Choice List”.

2e. Repeat the steps to create a “List of Values” for Department using the Departments view.

3. Create an Edit Page

3a. Make an Edit page for Employees. Create a new JSF JSP page in the ViewController project. Let’s name this page employeeEdit.jspx. If you feel like it, drag a panelHeader onto the page and change the label to “Employee Edit”.

3b. Open the AppModuleDataControl under the Data Controls pane on the left-hand side of JDeveloper. Open the DepartmentsView1 node and drag EmployeesView3 onto the panelHeader in your jspx page.

3c. The ManagerId and DepartmentId fields should show that the component is a choice list based on the UI Hint we provided to the View. You can change it here, but you do not have the option here to change it to a popup List of Values, to do that, you must change it back in the UI Hints on the View. Click on “Include Submit Button” and click “OK”.

4. Create a Task Flow

4a. Let’s create our first Task Flow. To do this, right-click on the View project and select New. From the menu, select Web Tier -> JSF on the right side of the wizard and ADF Task Flow on the left.

4b. Name the task flow masterDetail-task-flow-definition.xml. Make sure you don’t have “Create with Page Fragments” checked and click OK.

4c. In the properties of the task flow, on the behavior tab, set the data-control-scope to “isolated”. In TP4 it is set to “shared” by default and would therefore require a parent task flow.

4d. Drag a “View” component from the ADF Task Flow component toolbar onto the Task Flow design sreen. Name this View “masterDetail”. In the properties panel, set it’s page property to the masterDetail.jspx page.

4e. Drag another “View” component, set it’s name to “employeeEdit” and set the page property to the employeeEdit.jspx page you just created.

4f. Drag a “Control Flow Case” component and drop it onto the masterDetail View object. Then drag it over to the employeEdit View object. Name the Control Flow Case “edit”.

4g. Create a Control Flow Case going from employeeEdit to masterDetail and name it “return”.

4h. Back on the emoplyeeEdit.jspx page set the action for submit to “return”.

5. Getting it to actually Do Something

5a. To make the components lay out nicely, drag a panelGroup layout component over in between the department table and the employee table. Then drag the employee table into the panel group.

5b. Add a button to the panel group. Change the label on the button to “Edit”. Set the action to “edit”. Notice that the name you had provided in the Control Flow Case is available for use as an action for the button. This is a beautiful thing.

5c. Add Commit and Rollback buttons to the page by dragging them from the AppModuleDataControl.

6. Play With It!

You now have added a seperate edit page to the application, hooked it up using a task flow, and rolled all of it into one transaction, all without writing a single line of Java code. If you are a Java developer, you may be wondering what’s going on under the covers and I encourage you to dig in and find out! You’ll especially want to understand how task flows work and how the transactions are managed.

Anyway, I’ll leave as a next step for the student to add a create button.

Share/Save/Bookmark

ODTUG and a new Forum

I haven’t posted much in the last couple weeks, too much traveling, most of it business unfortunately.  Anyway, this is a quick update to be followed up with a more interesting how to article involved JDeveloper and ADF.  I hope to get that posted by the end of the week.

ODTUG is coming up in just one week.  It is being held in New Orleans this year, and if you get there early on Saturday you can be one of the many volunteers to help with reconstruction by, I believe, building a home.

I will be there from Saturday until Thursday.  My presentation is on Tuesday, June 17th, from 12:45 to 1:45 and is titled “Using ADF 11g as  Platform for Oracle Client/Server Forms Conversions.”

I hope to see you there!

On another note, Andrejus Baranovskis, an Oracle ACE director who works for Vgo Software and will also be presenting at ODTUG this year, has created a place to discuss all things regarding Oracle Form’s Modernization. You can find it here.  It is part of the Oracle Mix site, so you will need an account there.

Share/Save/Bookmark