Wednesday, September 12, 2012

Custom SelectionListener for af:table with select many option. ADF BC 11g

Hi,
In this example we are going to create a custom Selection Listener for an af:table.
Furthermore, we are going to investigate how the Selection Listener works in the case where the table gives the ability to the user to select more the one record.
After this example we will be able to understand what is going on in the above scenario.

Download Sample Application.

In this example we are going to use the HR schema and the table Countries. We will be using also JDeveloper 11.1.1.6.0.

The Requirement:
We would like to have a table of Countries where, we will be able to select more than one rows (Countries).
While the selection process takes place, we would like to see a label on the side that keeps updating with the names of the countries that are being selected. Furthermore, when a row (country) is deselected, the label will be updated again to reflect the names properly.

Simple right?
Imagine, all the people.. living all in peaace ou ouo ououou..
Now that I have your attention..
First we will generate the Business components.
A quick refresher can be found here.








After that is done, we are going to create our simple page with the af:table from that View object (Countries)


In order to enable the select many on our table. It is quite easy. It is just a property in the table.


I know, you can do it, while dropping the iterator onto the page. I preferred to show the property instead. Good for you to notice!

Right. Now we have to set our selection listener.
This is quite easy:
Just locate the selection listener

All we have to do now is to setup our custom Selection Listener.
Ou custom listener will be written in JAVA method in a JAVA class. So we have to create a new JAVA class and a method inside it. It will take some time right?
No. JDeveloper takes care of those things for you. Check the picture below:



In the small window, you can press new and you JDeveloper will create for you all you need.
In this example I placed the names shown in the screen.
So now, we already have our class, properly configured, and a method that accepts a Selection Event.

Prior to implementing this, in the newly created java class, we are going to keep the names of the selected rows in our table. We are going to that in the class that holds our custom selection Listener. We are going to create an instance variable of type String with it's accessors:



That String is going to hold all the names of the rows we select or deselect at runtime. Cool isn't it?

Remember, we are on a select many  situation here..

A question first.
if you create a method in your Application Module that will return the current row of our ViewObject. What do you think that it will return when we select 5 rows and immediately call it?

I dare you to try it! :) (The code is there in the sample application).
Well, as far as I know, you can get only one row as the current one. So, there must be one of the selected. (it is.. randomly, it is one).

So how are we supposed to do a custom selection for many records?
Exactly the same way as we would have done for a single selection. Simple. The code exists (Check out the references below for the links).
The difference that we are going to do here is to get the selected ones and loop over them in order to get the information we want and display it on another output text.
Eventually we will be having something like the following:



OK, on to the code


As you can see, it is a small addition. You have access to the rowKeys and thus you have access to the rows.


Download Sample Application.


References:
http://technology.amis.nl/2010/08/10/adf-11g-that-is-one-very-smart-toolbarbutton/

http://www.oracle.com/technetwork/developer-tools/adf/learnmore/23-generic-table-selection-listener-169162.pdf

Regards.

Monday, September 10, 2012

Where are the DB connections stored in JDeveloper?

Hi,
For those of you who ever wondered:
Where does JDeveloper hold all those DB connections??

The answer is:

Per Version:
11gR1
C:\x\system11.1.1.5.37.60.13\o.jdevimpl.rescat2

C:\x\system11.1.1.6.38.61.92\o.jdevimpl.rescat2
11gR2
 C:\s\system11.1.2.2.39.61.83.1\o.jdeveloper.rescat2.model

In those folders you will notice the following structure:






The most interesting part is the file inside the connections folder. if you open the folder you will see the file:
connections.xml
here is a sample part of that file:

      
      
         
            XE
         
         
            oraJDBC
         
         
            localhost
         
         
            hr
         
         
            1521
         
         
         
            true
         
         
            thin
         
      
   



hooray!! there is our connection!
We can simple take the xml and place it there! all will be fine!
Well, not exactly, if you notice the xml more carefully, you will see that there is no password information.. and you can easily guess that the cwallet.sso file must be holding those references.
Alright then! lets just copy those ones only.
To be honest, I just did it and I must say that I do not see any problems what so far..
The down side: You have to restart JDeveloper in order the changes to take effect. Which in my opinion, it will take more time to export and import properly.

In conclusion, we now know where the DB connections are stored in our various versions of JDeveloper.

I will still use export and import as the prefered process. 

cheers.

References:

http://www.baigzeeshan.com/2012/07/sharing-common-connections-between.html

Friday, September 7, 2012

Integrated Weblogic Domain creation. "The Server Instance cannot be started because the Integrated Weblogic domain was not built successfully." a workaround. JDeveloper

Hail,

This is a quick note regarding default domain creation in Integrated Weblogic Server.
This is a workaround that helped me and by no means, this is not a best practice. 
It is simply another approach and is provided as is. This is for my personal reference and notebook. It happened on a windows machine and frankly no specific answer, on the why this is happening came to mind, but a workaround was possible. I must say, that a lot of things learned during this investigation.

In case you are first trying to run an application from within JDeveloper an you get the following:

-------------------------------------------------------------------------------------------------------------
[Waiting for the domain to finish building...]
[11:56:47 AM] Creating Integrated Weblogic domain...
[11:56:47 AM] ERROR:  An error occurred while building the default domain.
Please see this log file for more details:
C:\X
XXXX\system11.1.2.2.39.61.83.1\o.j2ee.adrs\CreateDefaultDomain.log
The Server Instance cannot be started because the Integrated Weblogic domain was not built successfully.

------------------------------------------------------------------------------------------------------------
Before First, remove or rename your created DefaultDomain folder ( under system11.1.2.2.39.61.83.1 folder) 


First, open the log file as suggested by JDeveloper

Then, most probably, you will see something like the following:

-----------------------------------------------------------------------------------------------------------
Log File:      C:\XXXXX\system11.1.2.2.39.61.83.1\o.j2ee.adrs\CreateDefaultDomain.log
Label:         JDEVADF_11.1.2.2.0_GENERIC_120418.2212.6183.1
Product Home:  C:\XXXX\Oracle\Middleware\home22\jdeveloper\jdev\
Domain:        C:\X
XXXX\system11.1.2.2.39.61.83.1\DefaultDomain

"C:\XXXX\Oracle\Middleware\home22\oracle_common\common\bin\wlst.cmd" "C:\X
XXXX\system11.1.2.2.39.61.83.1\o.j2ee.adrs\CreateDefaultDomain.py"
Process started
Elapsed time:  47 ms
(<--- that was fast!)
----------------------------------------------------------------------------------------------------------
The CreateDefaultDomain.py script is the one that we have to call. but before doing this, we will edit it a bit..
If you try to run it as is, it is going to complain that you havent set an enviornment variable
Soo, you will simply add it in the created Script. This script is always regenerated when you recreate your system folder. After all it is just one line..

 =================================================================
import os
os.putenv('ADRS_DOMAIN_PASSWORD', 'welcome1')
if not 'ADRS_DOMAIN_PASSWORD' in os.environ:
  print("Error:  ADRS_DOMAIN_PASSWORD environment variable not set.")
  exit()
==================================================================

C:\XXXX\Oracle\Middleware\home22\oracle_common\common\bin>wlst.cmd C:\XXXX\JDevSystems\jdev22\system11.1.2.2.39.61.83.1\o.j2ee.adrs\CreateDefaultDomain.py

This will create succesfully your DefaultDomain for your integrated Weblogic Domain. Note that the domain is already extended by this script and *some* templates are added.

from the same command line you can navigate to the bin folder of your fresh Domain and start your WebLogic

C:\XXXXX\system11.1.2.2.39.61.83.1\DefaultDomaim> startWebLogic.cmd

This will start your integrated WebLogic.
you can test the console if you want (after you see the status in RUNNING) ofcourse.
my case: 127.0.0.1:7111/console

The ports might be different or the IPs.. but you get the idea.

What we have accomplished here is that you setup the DefaultDomain for the Integrated Weblogic without using JDeveloper and bypassing the problem of JDeveloper.

Of course we can be happy now! right? Not yet,
we have to check if everything is ok with JDeveloper.

Lets start JDeveloper now.
If you start JDeveloper, things are rather different than expexted..
JDeveloper thinks that DefaultDomain is not updated



This means that not all extensions are applied.. But where? where are those extensions??
The extensions can be found in the following path:

C:\XXXXX\system11.1.2.2.39.61.83.1\DefaultDomain\config\fmwconfig\adrs-domain-config.xml
If you open that xml file you will see the following:



This is the reason why Integrated Weblogic Server show the above error about domain updates.
If you try to update the domain through JDeveloper (right click update Default Domain), it will try to add the templates, even though the script we executed previously mentioned that everything was ok. The result will still be without success.

But, you can do it manually


   
      
      
      
      
      
      

   

These are the extensions, JDeveloper should have written in the xml file. After that, you should be able to see the integrated WebLogic properly and start and stop it at will.

For those of you that might get an authentication error while starting integratedWeblogicServer, the best approach I could find is to create a new Application Server Connection in JDeveloper pointing to the DefaultDomain. This will give you the flexibility to use the integrated WebLogic without having to install any additional standalone servers. JDeveloper provides a fancy UI for handling operations for integrated Weblogic..  With this workaround, we just managed to get the integrated weblogic started and working.
Again, this is just a workaround and not a solution and is not promoted as such.
Cheers!


Tuesday, September 4, 2012

ADF Business Components Extend Base Classes. Be cautious, All BC extend them. ADF BC

Hello,

NOTE: in this post, we are going to follow another approach of explaining things...
We are going to follow the first thing that it might come in mind. Then we are going to think it over and see the simplicity of things. This is an experimental way of approaching a matter and covers the case where things are not that clear in our mind regarding the best approach to follow. Sometimes I find people accepting solutions "as is" without considering to challenge them. With this approach, we are going to rethink some approaches in order to determine which is the simplest and best. Make sure that you read until the end. We are all busy and we want the solution fast. But, trust me, there is more into it than just accepting the solution.

This is another quick hint regarding extending business components base classes.

--wooow.. what do you mean by: "extending business components base classes"???

Well, with JDeveloper 11g you can set which classes will be extended by your business components..

--wooow.. what do you mean by "you can set which classes will be extended by your business components"??? (well, actually, this sentence must show a kind of mocking tone.. but I find it difficult to write it and not describe it.. )


Hmm.. I see.... Every Business Component (Entity, View Object, Application Module etc...) is described by an xml file.

For instance, in this example, we are going to create an ADF BC application that uses HR tables. Those tables are going to be Employees and Departments.

--wooow... what do you mean by "Employees and Departments "??

(I wonder... dude... where is my car??)
(--Just kidding..----- Oo --->)

For those of you who need a refresher about how to generate Business Components from tables, here is a refresher.

After we have generated the BC (do not ask me how... hit the link above.. above, not below..)

-woooow........................ just kidding..

Anyway, we have the ability to write some custom logic for all our View Objects, the ones already generated and the ones to be generated in the not so distant future, only once.

(where is the wooow now ha?)

-keep calm and carry on.. (I think there is a debate about that phrase, or poster.. something about copyright or something.. by the way I do not own anything of that phrase.. I do not own anything.. )
--wooow...

Lets say that we want to place some logging when executeQueryForCollection method is called on every View Object in our application.

-- I know! I know! I know! pick me, pick me pick me!!

okay... ( what the furniture aka wtf is that??)

--You extend the View Object's Class and you place the Logger there.

hoooray!! what about the rest 912783416293847162394817234912846434'1\234!@#$4#!@# View Objects??


---woooow...... what do you mean by that big number with characters that reminded me of Asterix and Obelix???

I mean, that there is a possibility to have more than a reasonable amount of View Objects to extend..
--soo? What is the problem? Are you lazy? is that it?

Yes, I do not want to keep extending and extending and going and going  (like that battery advertisement), repeating the same work over and over again... I want to be DRY

---woooow.. when did you got WET ??

....  "I have to return some video tapes" (which movie was it and which actor! the hidden challenge! Brought to you by dstas! The winner will get his/her name right here in this zupa fly post as the first correct answer! *No cookies involved* )

Alright..  lets do it in a different way..
Lets go to the Departments View Object! shall we?

--okay...

Do you see an java classes there?

--No.. there arent any....
Are you sure..
--Yeeah.. unless they are hidden.. are they hidden??

Yes! they are! you cannot touch this! Evil spirits and a big purple bear will hide the sunshine that goes through your morning orange juice glass and hits your spoon with which you eat your korn flakes!! No sunshine for you!!! (just kidding.. )

--wooow.. So lets generated them with JDeveloper.. It is simple dude.. Just press the pencil button and then check the darn check box! then press OK!! How difficult is that!!!!?????? See the screens below please dude.. you are killing me... you are really killing me dude..

oh God.. (choose whatever accent you want, but apply the "There is no salvation" tone please)



--There you go dude! It is ready..now apply your logger wherever you want..
Okay.. I will..
Oh wait a second.. what about Employees View Object? what should I do? I want to have the exact same logger there.. any hints?

-- Dude.. why are you blogging such dump staff?? Is not it obvious?? Just perform the same process. -----Good (oh no, I wanted to say Goood not good, it is a God with many oooo in order to emphasise the anger..)

Okay.. Lets pretend that I did that.. The great pretender.. Oh wait! I just got a message from the Boss via twitter (and received it more than 10 times since I am following, facebook, twitter, google+, LinkedIn and 10 other social or whatever else networks)  that  we have to create 300 View Objects more..

--Okay.. so?
....
Are you expecting me to generate all those java classes, are you?
--Dude, I know all hotkeys by heart (byHeart= ctrl+b+H)  in JDeveloper, I can work with out a mouse, I am a Ninja duper super masta gangsta waka mama loca Bosa Nova when it comes to using JDeveloper.. I can do it in a snap!

Okay.. I am not like that..
--Only the brave and the fittest and those with the Knowledge (The Horror, The Horror)  should handle such requests.

good God (spelled properly)..
Are You open to ideas?
--From you?? ahahaha... well, lets give it a try..

We could compete who is going to implement it faster, what do you say? You can throw all the ninja bomb smokes and asterisks you want.. what do you say?
--ahahahahahahah there is no way you can compete me on this!! Bring it on!

Here is my solution:

1) Create a new class that extends oracle.jbo.server.ViewObjectImpl;


-- 23 classes generated so far dude... I am on fire!!

2) Override the executeQueryForCollection method and place your logger (System.out for the simplicity here in this example)


--123 classes generated so far dude.... you are still in one class!! Not even a View Object.... I am even talking on the phone planning my next vacation dude!! That is what I call productivity with choice!!


3) go to your model project and right click-> properties. Expand "ADF Business Components Node" and select Base Classes. Then In the View Object value change the value from ViewObjectImpl to MyViewObjectImpl
--200 classes dude!!! What is that? What are you doing there?

Actually, I am done.
--What? yeah right..

Really, I am done.

--wooow... how did you do that? Just wait a minute... Is this applied to all View Objects???

The last screen shows which classes are going to be used by default by ADF when it comes to using the View Objects. By default oracle.jbo.server.ViewObjectImpl is going to be used for every View Object in our application.
--Aaaand how I am going to tell that a ViewObject extends my custom class properly???
It is very easy. Just go to your

All View Objects that do not have yet generated their java class, will use our new class.
In order to verify if this already done properly (There is a strange behaviour here see note below) Check the source of the xml file:


If there is no ComponentClass in the source file, the default ViewObjectImpl java class will be used.

========================================================================
NOTE: It seems that there is some "strange functionality in the versions tested 11.1.1.6.0 and 11.1.2.1.0" The change is not reflected until a View Object is edited. By edited I mean to check the Classes Extend of the view object.


You will see the custom class there, even though the ComponentClass tag is not generated in the xml source. By just doing this and the pressing ok the change will be reflected.
This a strange behaviour and it does not seem that right.
Another thing you can do is to manually set the ComponentClass tag to those View Objects that existed prior to extending the base classes.
========================================================================

All View Objects that already had their class generated, will not use it, unless we change the extension manually. All previous classes where extending the default one which was oracle.jbo.server.ViewObjectImpl.

All View Objects that will generate their class, will extend our custom class which is MyViewObjectImpl.java

--wooow.. that is smart... And what about my 200 classes? What should I do now?

Well since you generated them.. you will have to manually update the extends part to the custom ViewObjectImpl class that extends the oracle.jbo.server.ViewObjectImpl class

--woow... Thanks Dude.. That was really nice and fast!

Yeap. One thing to remember here is that a careful design is needed when it comes to extending base classes of BC.

One must always keep in mind that all BC (depending on what you extend of course) will use the Base class that you will define. So, for example, if you have a base class with abstract methods, all ViewObjects that have not generated their classes (and have properly set the ComponentClass tag in their source.), will throw an exception!!
You could see something like the following:

(oracle.jbo.JboException) JBO-29000: Unexpected exception caught: java.lang.InstantiationException, msg=null 

Cheers!


Sunday, September 2, 2012

Installing graphics libraries and desktop services componen[FAILED](See the log file /var/log/vboxadd-install-x11.log for more information.

Hi,
Just a quick note here.
I was trying to install my new Guest Additions to my VirtualBox
4.1.14 to 4.1.18 all of a sudden I got the following exception

Installing graphics libraries and desktop services componen[FAILED](See the log file /var/log/vboxadd-install-x11.log for more information.

By all means, do not restart your machine! I did and I could not log in to my CentOS..
so I had to restore my machine to a previou snapshot that worked....
I tried again, and got the same error.
This I searched the internet and I found this forum thread that helped my solve the problem

https://forums.virtualbox.org/viewtopic.php?f=3&t=49334

All I had to do is to remove the VirtualBoxGuestAdditions symlinks.
 The commands to be executed are the following:

> rm /usr/lib64/VBoxGuestAdditions
> rm /usr/share/VBoxGuestAdditions


A big thanks to the guys that found that solution!
Lessons learned: Always remove the VBoxGuestAdditions symlinks prior to installing the new VBox Guest Additions.
Just to be on the safe side..

cheers.

LinkWithin

Related Posts Plugin for WordPress, Blogger...