I write solutions to the problems I can't find much about elsewhere on the Web, also some code/script snippets that are absolutely awesome and make my life easier. Will be glad if someone finds these posts interesting and helpful!

Monday, May 3, 2010

Accumulative sorting in ADF 10g tables

Just what the title says.

In an application there were a few tables filled with results of some queries. I haven’t yet figured out why, but it was of a high importance to the client that all the tables had accumulative sorting (like the order by clause in SQL). This requirement took me a while to figure out how to implement, whilst the solution was quite elegant and pretty small to write it here.

So, there’s a table with results of a search (the query really doesn't matter as the entire sorting solution will be implemented in the view layer)

The whole trick is to set sortListener=”#{CustomersBean.onSort}” for the table. The backing code for this sortListener is found in the backing bean named CustomerBean.

And that’s pretty much it. The table is now sortable accumulatively: you can hit customerid first, then name, then surname etc. the resulting table will look similarly to what produces SQL clause order by customerid, name, surname, etc.
Hope this helps.

“javax.faces.convert.ConverterException: Unsupported Model Type” in ADF 10g for selectManyCheckbox

There’s a mess with the selectManyCheckbox bindings: for both initial list items and selected items. ADF itself doesn’t support direct binding to a ViewObject, and that’s why, as Frank Nimphius said,
…you would need to use a managed bean to dispatch between the ADF binding layer and the multi select component.
Maybe it’s just me, but it took me a while to figure out how exactly to do it.


First off, the managed bean. It should contain fields with accessors for two lists: the initial options and the selected items.

The initialListItems will be bound to the multi-selection items element. Whilst the selectedItems list will contain the selected items from the initial list. The important thing is the datatype for the latter – a java.util.List! In fact it’s what provokes the “Unsupported Model Type” exception. This datatype hassle was actually the part that took me a real while to get it, I tried primitive array, ArrayList of String’s, Object’s and what not!
Now the only thing left is to bind both lists to the multi-selection component.

No more exceptions. That's it, hope it helps!

How to add showPopupBehavior to an ADF Rich Faces table column

I didn’t see the answer to that anywhere in the manual, so I had to experiment myself. Ofc I sort of figured out how to do it pretty easily. Still this tutorial can save someone’s time, I hope.
So, basically, what one can do to pop a dialog with ADF Rich Faces, is 2 simple steps:
1. Define a popup with a dialog in it
2. Set showPopupBehavior of the link or button to point to that popup.

Pretty simple, isn’t it? Now the question is how to achieve the same behavior per row in a table. If we set the same showPopupBehavior popupId to a command object found in a column, it won’t work and JDeveloper will mark it as an erroneous syntax (“Reference Id confirmDelete not found”). Well, the trick is that the popup should be defined inside the column, and that’s actually it. Here’s a code snippet.

The method in the backing bean looks like:

The navigation part is intended to refresh the page (there’s a global rule in the faces-config.xml for outcome “scheduler” to navigate to this page), because dialog handler doesn’t do it automatically with JSF controller.
Hope this helps!

How to make the Oracle Application Server 10g run as a Windows service

A problem that recently has been bugging the project I’m currently working on, was to make the Oracle Application Server 10g run as a service, so that it would be available without a user logging in and starting it up manually. We solved it with the use of an open source middleware project called JavaService, a pretty neat tool. Find below how.

Requirements:
Windows machine (the guide was tested with a vanilla Windows 2003 server installation)
Oracle Application Server 10g
The latest version (today 2.0.10) of JavaService

Actions:

Let’s say JavaService is unzipped to C:\JavaService-2.0.10
Then from the JavaService-2.0.10 directory execute:

Now the service OAS can be found among other services.

Should be also mentioned, that the Application Server better be stopped by the time you attempt to start the service.

Hope this helps.

Global validation for a Date input field in ADF 10

Say you have a table with a date column and you have created a view accessing it. Now try to insert an abnormal date into the dateInput field on the page (something like 1/1/111111111), commit the changes, check the value in the DB and you’ll get what I’m talking about here. I had queried a question on the OTN forum regarding this and the only answer I got was from Frank Nimphius to
configure a value change listener on the date field and verify that the provided value is valid, If not call FacesContext.renderResponse to ignore the request
this is a solution, but well, it requires more or less to apply it to each dateInput field on every single page. The other way around that I finally used, was to override the EntityImpl setAttributeInternal method like the following:

which actually just checks that the Date attribute provided is of a logical range.


This method has to be part of a class extending oracle.jbo.server.EntityImpl and obviously the entity implementation for that table with a date column must extend the new EntityImpl class.


That's it. Hope this helps!

Oracle database schema data removal

In my previous post I mentioned a script I used to drop everything from the schema, and I thought it could come handy to someone, hence here it is:

This script has been extensively tested on Oracle 10g for all kind of editions and seems to work awesomely!
Beware, this WILL REMOVE EVERYTHING FROM THE DATABASE SCHEMA FOR USER YOU HAVE CONNECTED AS; that is if you connect as sysdba, it will most likely make the database useless.

Clear an iterator in ADF 10g

The mission is to empty out an iterator without setting its Refresh attribute to “never” and consequentially executing it manually. What I ended up doing, when I needed this once, was adding a parameter to the query WHERE clause (something like “and 1 = nvl(:param, 1)”) and invoking it with a zero when I needed it empty. Apparently there is an easier way.
Say the iterator to clear is defined in the pageDef as:

Then the code in the backing bean would look like:

That’s it. Hope this helps!

Service management in Windows

Go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services in Registy Editor (regedit.exe under WINDOWS\system32), there lookup the service by name. Properties appear on the right of the tree.
One property that can be surely needed at some point is the location of the executable of a service. That’s the property ImagePath.
Whoever has set up an Oracle Database instance knows what I’m talking about here The story behind that, is that I made the mistake to run the script which drops everything from my scheme, whilst I had connected as sysdba Yeah, I know.. stupid. Well, not the first time Anyways, the thing is that during second set up, Oracle DB seems to highly dislike the previous instance and does not alter all the services correctly (oh, I just hope that it wasn’t left intentionally, because that would mean, the developers aren’t human beings). E.g. the OracleCSService (something to do with clustering) doesn’t shut down correctly and consequentially during the second set up the path doesn’t change. Here I had to change the ImagePath for it at the location HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\OracleCSService. As simple as that.
The truth be told, I still haven’t figured out how to properly set up a fresh instance after removing the previous. Sounds like a story for another post.

P.S. After quite a research I found a great post about a complete removal of the previous installation. Find it here. I tried the method described like a hundred times already and it seems to work perfectly.

Silently print Jasper reports

I’ve recently come across an issue with the project I’m working on regarding what the title says. The thing is that the users didn’t want to see any kind of dialogs prompting to print the report. Well, it was pretty easy after all and the class I wrote follows.

And here’s a usage sample:

Hope this helps anyone.