Tuesday, June 29, 2010

Populating primary keys with DBSequence

There could be may scenarios where we would need to populate primary keys with DBSequence. If this is the
requirement then best place to populate them would be initDefaults() method of EOImpl.java
Open the EOImpl.java file and overwrite initDefaults() as shown in sample code :

@Override
protected void initDefaults()
{
  super.initDefaults();
  SequenceImpl seq = new SequenceImpl("SEQ_NAME", getDBTransaction());
  populateAttributeAsChanged(CONTRACTID, seq.getSequenceNumber());
}

CONTRACTID is the name of the attribute identifier and  SEQ_NAME is the name of the Sequence.

Monday, June 28, 2010

Opening PDF, TXT or DOC Files in ADF.

Opening .pdf, .txt and .doc/.docx file in application is very common requirement. In ADF this could be achieved very easily by af:goLink component. Here is the code snippet for the same:









important part here the location of these files. This files should be located inside public_html folder of your View Controller project.

Wednesday, June 2, 2010

Creating a Java Web Service using JDeveloper

Creating and testing Java Web Services could really be simple using JDeveloper. Let’s see how can we create a java service and test it in JDeveloper.

1. Create a project and Java class.
In Jdeveloper, click on File->New and choose General->Application in categories column. Select Generic Application and click Ok. Provide Application Name and Project Name in wizard and click ok.
Right-click on the project in Application Navigator and select New from context menu. In New Gallary window, select General->Java under Categories and then select 'Java Class' in Items section and click ok. In Create Java Class wizard, give a suitable name to class and set other properties as needed and click ok.
2. Add methods that need to be exposed as service


3. Create web service from the java class.
    Right click on the class and choose 'Create Web Service'. Rest follow the wizard for the completion. If you are not looking for any specific configuration, you can keep all the default setting in wizard. When wizard end's your service is ready to be deployed.
    Please note annotation @WebService at the start of the class, this is what makes this class to be recognized as web services.
Test your service.
    Right click on the java class and choose Test Web Service option from the context menu. This will deploy the service to Integrated Weblogic Server. Jdeveloper by default provides an interface (HTTP Analyzer) that could not only be used to provide input and receive output but we could also view WSDL, SOAP and HTTP messages.



Really simple, isin't ?

Code Ninja Chronicles - Oracle ADF

Does Oracle ADF rocks? Well at presents it is a debatable issue and which ever side you end up, I guess we all agree that every framework and or technology has its bright and dark side. However Oracle's turning each possible stone to get ADF to its pinnacle.

Here are couple of videos to enjoy:





If you want to be one of the code ninjas using ADF, this is were you can start.

Tuesday, June 1, 2010

Error: Unable to create JAXBContext

Well, few weeks back I was experimenting if I could create a java web service having a method that excepts XMLDocument or XMLElement as argument or probably return the same. While trying to expose this java class as services I constantly hit error:


javax.xml.ws.WebServiceException: Unable to create JAXBContext
at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:158)

................
Caused By: java.security.PrivilegedActionException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
oracle.xml.scalable.InfosetReader is an interface, and JAXB can't handle interfaces.
...............
Caused By: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
oracle.xml.scalable.InfosetReader is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at oracle.xml.scalable.InfosetReader
at public oracle.xml.scalable.InfosetReader oracle.xml.parser.v2.XMLDocument.getInfosetReader()
at oracle.xml.parser.v2.XMLDocument
at public oracle.xml.parser.v2.XMLDocument testws.jaxws.TestXML.arg0
at testws.jaxws.TestXML
oracle.xml.scalable.InfosetReader does not have a no-arg default constructor.
this problem is related to the following location:
at oracle.xml.scalable.InfosetReader
at public oracle.xml.scalable.InfosetReader oracle.xml.parser.v2.XMLDocument.getInfosetReader()
at oracle.xml.parser.v2.XMLDocument
at public oracle.xml.parser.v2.XMLDocument testws.jaxws.TestXML.arg0
at testws.jaxws.TestXML

I reported the issue to Oracle forum and found that JAXB could not marshal these classes and hence Jdeveloper pops this error. So currently either you can use classes that have default data bindings in JAXB or probably need to write your own binding file or as a workaround you can either use Object type.

Well if there are any other methods that are causing this issue and you do not intend to expose them as service (which wasn't my case), annotate these method by @WebMethod(exclude=true). Currently JDeveloper doesn't annotates by default but hopefully this functionality will be added in future (Bug 9749573 is already logged for this issue)

How to configure CSS editor in Jdeveloper for ADF Faces RC?

Please do follow below steps to configure JDeveloper for CSS:
1. Got to Tools-> Preferences -> CSS Editor
2. Set ‘Support CSS Level’ to CSS Level 3
3. Check ADF Faces Extension checkbox.