Tuesday 16 December 2014

Oracle ADF - show/hide an area that is displaying af:messages

 

Oracle ADF has a very nice component af:messages that can show out of the box messages on the page.

This component has 2 modes. Default – it is shown as popup and second one, to be shown as inline component.

Inline mode is preferred, since it is less annoying than closing all the time popup and generally people don’t like popups since it reminds them about all commercial that pops up almost on every web site.

To switch the af:messages to the inline mode all you need is to set inline=”true”.

But since now your message is part of the page it actually takes some place that is used to display it.

It would  be much better if your messages will appear only on demand and occupy display space also only when needed.

It can be achieved very easily by using panel stretch layout. Just place messages component into “top” facet and set facet height to “auto”

image

 

Sample workspace (11.1.2.3) can be downloaded here

Sunday 19 October 2014

<unable to fully process the TLD cache for the following reason: While preloading the CachedConfigTable.. java.util.zip.ZipException: invalid entry CRC

 

I got this error with Jdeveloper 11g R1.

Don’t know why, because a day before this when I left the work everything worked fine. Today, when I came back and tried to run the application I got this error.

After “fighting” it for several hours, I just deleted the Default Domain and it solved the problem. Of course it is not a solution for Production , but allowed me to continue the development

Tuesday 14 October 2014

Broken mouse pointer in Jdeveloper 12c and Sqldeveloper 4.0.2 under Fedora (20) Linux

Hi. I recentrly installed Jdeveloper 12.1.3 and found that there is completely mismatch between the application menu and the place on the screen I am clicking with my mouse. I mean  - to click on the "File"  menu I actually have to click about 20px to the right and 10px to the left of the actual "File" location on screen.
   Probably it is some JDK bug.
Not sure about the fix, but the workaround is just set the DESKTOP_SESSION=mate before starting the Jdeveloper.


I also experienced the same issue on the same OS with sqldeveloper 4.0.2
I was able to run it fine  by setting
export AWT_TOOLKIT=MToolkit
before starting the sqldeveloper

Tuesday 5 August 2014

Solution for weblogic.jdbc.wrapper.Blob_oracle_sql_BLOB cannot be cast to oracle.sql.BLOB

 

If you have a web application and it uses SQL to work with BLOB data types, you may run into the following error:

weblogic.jdbc.wrapper.Blob_oracle_sql_BLOB cannot be cast to oracle.sql.BLOB

This is because Weblogic wrappes data types for some reason with his own classes. The solution is very simple . Go to the connection pool of your data source –> Advanced and uncheck “Wrap Data Types” check box

image

Sunday 18 May 2014

Solution for ORA-00603: ORACLE server session terminated by fatal error when compiling PL/SQL package

 

I was running some installation of DB objects with “sqlplus” utility and this is what I got

SQL> @XX_OM_DRH_PROCESS_UTIL.pkb

create or replace package body XX_OM_DRH_PROCESS_UTIL is

*

ERROR at line 1:

ORA-00603: ORACLE server session terminated by fatal error

The sad part is that the package is OK. If I open it in “PL/SQL Developer” I can compile it without any problems. But if I run it through “sqlplus” or “alter package XX_OM_DRH_PROCESS_UTIL  compile” it gives me the error above.

I spend several hours trying to understand what can be wrong. One of my managers eventually provided the solution. All you need to do is to execute the following

SQL> alter session set events = '10932 trace name context level 32768';

Session altered.

SQL> @XX_OM_DRH_PROCESS_UTIL.pkb

Package body created.

SQL>

Sunday 30 March 2014

Oracle ADF “Create Insert” into read only table

 

The following related to Jdeveloper 11g (11.1.2.3)

Sometimes you want to present the data in the table as read-only, but still provide an option to create a new record by using build-in “create insert” functionality. Obviously we need some king of mechanism to make existing records “read-only” and new record to be “editable”.

Lacily for us  where is a property in Entity Object attribute called updatable. You can set its value to “While New” . So it will not be updatable all the time except when you are trying to create a new record.

But many times this is completely useless feature.

Consider the following table

create table xx_adf_demo (key_column number,customer_id number) 

image

I can define customer_id  “While New” , but it doesn’t give me anything since end-user is not interested to see the customer id , but customer name. So I need to join “xx_adf_demo” with some other table/view that holds the “customer_name”.

So my View Object will not be based only on the Entity Object , but also on some other table.

The good new I can see now the customer name. The bad news  - this field is not based on the Entity Object and there is no “While New” option in View Object attributes. For now we will just set it to “Always”

Here is the solution.

I will start by defining the sequence for “key_col” attribute and setting it into default value for this column.

create sequence xx_adf_demo_s
minvalue 1
maxvalue 9999999999999999999999999999
start with 115
increment by 1
cache 20;

image

we will also define a new transient attribute called “isReadOnly” of Boolean type and “Updated” Always

clip_image002[12]

Generate View Object Row java class and modify the “getisReadOnly” function

if (getEntityForAttribute("TagId").getEntityState() == EntityImpl.STATUS_NEW)
                    {
                      return Boolean.FALSE;
                    }
                    else
                    {
                      return Boolean.TRUE;
                    }

 

By using this code “isReadOnly” flag will be automatically set for “false” when row state is new.

Create another View Object to hold the LOV for customer name and assign it to customer name attribute in XxAdfDemoVO View Object.

clip_image002[10]

Now create you GIU by dragging the View Object, Create Insert, Commit and Rollback Buttons to the page (Place the buttons in the Panel Collection toolbar). When you dragging the View Object to the page – choose to drop it as “Adf Table…”

clip_image002[8]

 

If we run it now as is we will get

clip_image002[6]

We see that “customer name” column is not read only. Also note the value of “isReadOnly” column

Only small modification needed to achieve what we need. Modify “Read Only” property of “CustomerName” LOV to be #{row.isReadOnly}.

clip_image002[4]

Save and refresh the page. Click on the “CreateInsert”.

clip_image002

 

We are done.

You can download the workspace from this link

Tuesday 4 February 2014

Show BI Publisher Report in Oracle ADF page – with Java API only

 

The following was developed with Jdeveloper 11g R2 (11.1.2.3) and BI Publisher 10g.

My task was to allow user to download some data from the web - site in the “Power Point” format. The data is dynamically generated so PPT file need to be created each time user click the “download” button.

Oracle Bi Publisher  (OBP) is the obvious choice about what is the framework for PPT file generation. OBP can take XML source data , apply it over RTF template (which OBP knows how to convert to XSL-FO) and create different output types (PDF,Power Point,HTML…).

   First step was to generate the XML file. Actually we could do it with extracting XML from VO, but I will show how can we avoid this.

   OBP has something called “Data Template”, which is also the XML file. The purpose of this XML file is to define the SQL that will be used to extract the data and to define the structure of the XML file that is later used as a Data Source.

First of all we need to obtain the JDBC connection. We will get it from the web-logic Data Source

image

Now create some data in the database

CREATE TABLE Catalog(CatalogId VARCHAR(25) PRIMARY KEY, 
Journal VARCHAR(25), Publisher VARCHAR(25),
Edition VARCHAR(25), Title Varchar(45), Author Varchar(25));
 
INSERT INTO Catalog VALUES('catalog1', 'Oracle Magazine', 'Oracle Publishing', 
'March-April 2006', 'Commanding ASM', 'Arup Nanda');
 
INSERT INTO Catalog VALUES('catalog2', 'Oracle Magazine', 'Oracle Publishing', 
'May-June 2006', 'Tuning Your View Objects', 'Steve Muench');
 
INSERT INTO Catalog VALUES('catalog3', 'Oracle Magazine', 'Oracle Publishing', 
'May-June 2006', 'Managing Oracle Portal', 'Aradhana Puri');



Get the connection from the Web Logic

 javax.naming.Context initialContext = new javax.naming.InitialContext();
 javax.sql.DataSource dataSource =  (javax.sql.DataSource)initialContext.lookup("jdbc/Conn");
 Connection          connection = dataSource.getConnection();




Create XML data from “Data Template”


DataProcessor dataProcessor = new DataProcessor();
dataProcessor.setDataTemplate("C:\\Users\\Unitask\\dataTemplate.xml");
 
dataProcessor.setConnection(connection);
dataProcessor.setDebugLogOn();
                        
dataProcessor.setTraceOn();
ByteArrayOutputStream out  = new ByteArrayOutputStream();
dataProcessor.setOutput(out);
dataProcessor.processData();
                        
byte[] data = out.toByteArray();
ByteArrayInputStream istream = new ByteArrayInputStream(data);
System.out.println("Done data template");
                        



Convert RTF file to XSL-FO


 RTFProcessor rtf = new RTFProcessor("C:\\Users\\Unitask\\Doc1.rtf");
 ByteArrayOutputStream outXslFo  = new ByteArrayOutputStream();
                        
 rtf.setOutput(outXslFo);
 rtf.process();
                        
 byte[] dataXslFo = outXslFo.toByteArray();
 ByteArrayInputStream inXslFo = new ByteArrayInputStream(dataXslFo);

Merge XML Data and XSL-FO to generate a power point


FOProcessor processor = new FOProcessor();
                    
processor.setData(istream);
processor.setTemplate(inXslFo);
processor.setOutput(outParam);
processor.setOutputFormat(FOProcessor.FORMAT_PPTX);
 
 processor.generate();
 System.out.println("Done power point");
 outParam.flush();    
 
 



Now to make all this working in Jdeveloper, you first of all need to add a lot of jar to the CLASSPATH. To get the jar files you need to download “Oracle BI Publisher for Desktop” from Oracle web site and install it. After installation go to (I didn’t change the default installation folder) C:\Program Files (x86)\Oracle\BI Publisher\BI Publisher Desktop\Template Builder for Word\jlib and the following jars to your ADF application


image


Note: You actually don’t need the ojdbc6.jar file


Build a web page with a button that has “fileDownloadListener”


<af:commandButton text="Export" id="cb1">
     <af:fileDownloadActionListener contentType="application/vnd.ms-powerpoint"
             filename="biOutput.ppt"
             method="#{backingBeanScope.biBean.sendPtt}"/>
</af:commandButton>










“sendPtt” is the method in the managed bean that is executing exactly the same code I posted above.


This method out of the box gets OutputStream

 public void sendPtt(FacesContext context, OutputStream outParam) throws IOException

and it is used to write the the request output stream. You can see that we use it in this line of code

 processor.setOutput(outParam);



Now what is you also want to display the data to the user before he/she performing the actual “download”? Not a problem. You cannot present power point in the borwser, but who said it should be a “Power Point”. User only want to see it and doesn’t cares about the format. So you can generate the same output in HTML or PDF and embed into your page.


I created the servlet (called it “report”) and used the same code, but this time I asked to create a PDF output.


In my ADF page I used “Inline Frame” component that I pointed to “report” servlet


image


Now when user starts the page , he can see the data and also to download it as “Power Point”


image


You can download the workspace and RTF and Data Template bellow


Workspace


OBP Files

Wednesday 22 January 2014

Oracle ADF. Master-Details relation with “details” being displayed as inline row details

 

This post was developed with Jdeveloper 11g R2 (11.1.2.3)

ADF supports out of the box master details relation. You can define the View Link and drop the child VO from the “Data Control” section and ADF will ask you what kind of “Master-Details” do you want to create. If you choose “Master table – Details table”, the ADF will generate for you 2 table one above other.

   However it may be much nicer to display the detail table inline with master row.

Note!!!! Don’t confuse it with a “tree” component

I will use the HR sample schema from Oracle to present the employees of specific department.

First of all we will create the model. Do not create the View Link between “Departments” and “Employees”.

For department just create VO based on SQL

select * from departments

select * from departments

image


For employees create VO with bind variables


image


 


Our idea will be the following. We will display the details in the iframe component.


Create new bounded task flow.


image


In the property of the flow make the following changes


image


It means that you can directly access this task flow from URL and it accepts the “pDept” parameter


Drag “exceute with params” from Data Control for Employees VO and use pageFlowScope.dept value (that we used to store the URL parameters) as input parameter


Create new page view to display the “Employees” table.


image


image


Test your work by running the task flow XML


image


You will be prompted to enter the parameter. Put some value (I put 60).


Note the “pDept” appears in the URL.


image


Now create a page and drag to it the “Departments” VO from the data control


image


Add to the table “detailsStamp” facet and insert into the facet the “inlineFrame” component


image


For the frame source , put the url to details-flow XML file and use “department id” as dynamic parameter


 


image


Run the application


image


image


Download the workspace from this link


 


 



Thursday 9 January 2014

Oracle ADF – hide search icon from af:inputListOfValues or true autocomplete

 

The example bellow shows how to hide the search icon “search glass” from adf inputListOfValues component so it will look like regular auto complete field that we see all over the Web

The example was developed on 11g R2 Jdeveloper.

This is the result

clip_image002

 

clip_image002[4]

Doing this is extremely easy. Actually what you see is just a VO that I dropped on the page as a Form. “Item” has LOV defined in the “model”.

So when I dropped the VO on the page, the LOV was automatically created for me .

I used “suggestedItems” to create auto complete list as described here.

How all I have to do is to remove the “search” icon. For this I created a CSS style class and put it into application CSS file. How to create a CSS file for ADF application can be see in this grate post

Here is the Style Class

.TagSearchIconHidden af|inputListOfValues::search-icon-style

{

display: none;

}

And here is the usage of this class in “StyleClass” property for “Item” field

 

clip_image002[6]