Sunday, October 14, 2012

Configuring KeyStore credentials in JDeveloper


In order to authenticate to https services, the server side public certificate must be acquired and added as a trusted cert entry to a keystore used by the client.  This certificate can be imported using the browser as shown in the screen shot below. This keystore stores a reference to the public certificate of the service and will be using some alias. The certificate for a web service can be obtained from the service WSDL url. Save the imported certificate to local drive.



Import Service certificate to a keystore file
·         keytool -importcert -alias testkey -file servicecertificatefile.cer  -keystore  .\my-keystore.jks -storepass keystorepassword

Tip:  keytool utility can be found the path <jdk_install_dir>/bin

List the contents of a keystore
·         keytool -list -keystore ".\my-keystore.jks"

Steps to specify the keystore that JDeveloper should use for handling https traffic:
·         Go to Tools à Preferences
·         In the LHS tree node select credentials
·         Configure the Client Trusted Certificate Keystore pointing to the my-keystore.jks location created earlier and provide the key store password




Saturday, October 6, 2012

Programmatic approach to insert record in ADF


Best approach to create or insert a row in the table which requires some custom logic to be built which needs to be called and after processing the data is to have the method which inserts/creates the row in the Application Module implementation class. Then create the data control of the method. Then bind the method to the view , where backing bean would call this create method.

Below given code is the one,which will be the method in AppModuleImpl.java. To see this class you will have to go to the AppModule.xml in Overview mode  and then click on the Java tab. Click on the edit icon which looks like a pencil and then generate the classes.



public String create(Integer a, Integer b, Integer c,
                              java.util.Date d) {
    String result="Create Complete!";
    AttributeList at = new AttributeListImpl();
    at.setAttribute("A", a);
    at.setAttribute("B", b);
    at.setAttribute("C", c);
    at.setAttribute("D", d);
    Row row = getCase1View1().createAndInitRow(at);

    at.setAttribute("A", a);
    at.setAttribute("B", b);
    at.setAttribute("C", c);
    at.setAttribute("D", d);
    this.getEmp1View1().getDBTransaction().commit();
   
      return "created";
     
  }


To expose the method as a data control, you need to click on the Client Interface  edit icon and then select the method and save. This process will create a client interface java class which will expose the method as a data control. Which can then be binded to the view.


Then the below given code can be used in the managed bean to call the method binded.

         DCBindingContainer bindings =
        (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();

        OperationBinding op = (OperationBinding)bindings.getOperationBinding("create");
        op.getParamsMap().put("a", 1);
        op.getParamsMap().put("b", 1);
        op.getParamsMap().put("c", 1);
        op.getParamsMap().put("d", new Date());
        op.execute();


Thursday, October 4, 2012

Programmatic Data Retrieval in ADF



// Get the binding context and the binding entry for the current view.
DCBindingContainer bindings =  
(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
   
// Get the iterator binding instance from the iterators binded to the view
DCIteratorBinding it = (DCIteratorBinding)bindings.get("UsersView1Iterator");
   
// Retrieve the view object instance from the iterator binding, this would have the result set.
// Set the where clause with the attribute and view name
ViewObject viewObject = it.getViewObject();
viewObject.setWhereClause("USERNAME = '" + username +"'");
   
// Execute the query to retrieve the record
viewObject.executeQuery();
     
   
// Retrieve the Row from the row set retrieved
// viewObject.hasNext() can be used to iterate through the row set.
Row r = viewObject.next();
   
// Now obtain the value from the retrieved row.
String userid = r.getAttribute("AccountId").toString();
   

Friday, August 24, 2012

ADF Security


Implementing ADF Security

By default the in an ADF application the security is not enabled. For people who have worked on Webcenter Application Template would actually notice a difference. As in Webcenter portal application it is enabled by default. But in ADF application you can enable ADF security by following the below screen shots easily. When you enable ADF security in an ADF application a jazn-data.xml file gets created. This file stores all the security related configuration done by the user at the design time. You can create users, groups, roles in this file and then grant permission for the resources such as taskflows, pages etc. When the application is deployed on the weblogic server then the users are created at the server level. Using the ADF security configuration wizard you can also generate the login.html and error.html files as well as configure the welcome/home page after user successfully logins. 
All the security related information of the authenticated user can be retrieved from the ADF security context object. This object can be accessed in the managed beans as well as the web pages. To access the object in the web page you would need to use the expression language.










I would also like to share an article on ADF Security from Frank Nimphus. Below is the link for the same:



Thursday, April 12, 2012

ADFBC - Dependent LOV with a create form.

Found that people are still having issues with creating dependent LOV and use the same to show up in create mode for the forms. Below steps describe the scenario devlopment and also given is the link to download the sample project.

Note: Development of the sample is using the pre-installed hr schema in the Oracle XE database, Using Jdev 11.1.2.x:

Step1: Create a new ADF application named 'ADFBCApp'.

Step2: Create the database connection (either using the Application overview that opens up on application creation or by using the new connection ) to the hr database schema.

Step3: Create the EO and ViewObjects for 'Countries' and the 'Locations' tables from the hr schema. Make sure when the EO and VO's get generated the App Module is checked so that the vO's get exposed as data controls.

Step4: Open the LocationsView.xml file which has got generated in the Model project if you have selected Model as the project during ADF BC generation.

Step5: Goto the Attributes tab. Select the CountryId attribute. Click on the List of Values tab and then click on the "+" sign. A wizard opens to configure the LOV. In the wizard now select the data source by clicking the "+" sign, that would be "CountriesView1"  and then select the  list attribute to be CountryId. In the UI Hint select the CountryName as the UI Hint to insure that the name of the country appears in the dropdown instead of the non user friendly "CountryId".

Step6:
Create a new view object for StatesViewLOV. This will be a SQL query view object, use the below given query to achieve the same.

SELECT distinct
    LOCATIONS.STATE_PROVINCE STATE_PROVINCE
FROM
    LOCATIONS
where country_id=:p_country
Also, add a bind variable to the SQL Query view object named p_country. It the same as the one used in the query.

Step 7:
Now open the LocationsView1.xml in Overview mode again. Navigate to the Attributes tab. Select StateProvince attribute. And add the LOV to the attribute as mentioned in step 5. But make sure you select StatesViewLOV instead of CountriesView1 as data source.

Step 8:
Now create a ADF bounded task flow (name it as task1) and a form1.jsff view file. Drag and drop the LocationView1 data control from the data control tab on the application navigator on the jsff page and select ADF form with submit button checked as the view component to be binded.

Step 9: For the CountryId select one choice component, in the Property inspector make the AutoSubmit property to be true. Then for the StateProvince field set the partial trigger attribute in property inspector to the CountryId field id (ex: soc2).

Step10: Now drag and drop the Create operation from the LocationsView -> Operations data control on the taskflow  diagram view. Then Drag and drop the jsff created. And link the two from Create operation to jsff using the ControlFlow component in the component palette. Keep the link event to be as it it. And save all the changes.

Step11:
Create a jspx page(name untitled1.jspx in the sample project) and then drag and drop the task1 taskflow from the Pageflows folder on the jspx page and select Region as the option for view binding.
Now run the untitled1.jspx page to see the Dependent LOV in create mode working.

Please use this link (ADFBCApp.zip) to download the sample project.
  

Saturday, March 10, 2012

iPad Support for ADF

Coolest stuff in Jdev and ADF release 11.1.1.6 is:
ADF Faces and DVT components are now certified on iPad. 

All the ADF Faces and DVT components now support touch gestures for interactivity on the touch-enabled devices. 
Also, touch support has been enabled for :
1. Drag and Drop
2. Tooltips
3. Data tips
4. Context menus.  
This support is enabled through the new v1.2 version of the FusionFx and FusionFx-simple families of skins.   

Tuesday, January 31, 2012

To retrieve the Oracle BPM worklist payload in ADF taskflow


// Get the faces context object
FacesContext context = FacesContext.getCurrentInstance();

// get the worklist context and taskid (of the task selected), these are by default part of the page
//flowscope in the BPM workspace where the taskflow will be included
String ctx = (String) context.getApplication().evaluateExpressionGet(context, "#{pageFlowScope.bpmWorklistContext}", String.class);
String tskId = (String)context.getApplication().evaluateExpressionGet(context, "#{pageFlowScope.bpmWorklistTaskId}", String.class);

// Get the workflow service client and task query service
IWorkflowServiceClient workflowSvcClient = WorkflowService.getWorkflowServiceClient();
ITaskQueryService wfQueryService = workflowSvcClient.getTaskQueryService();
IWorkflowContext wfContext = wfQueryService.getWorkflowContext(ctx);
Task myTask = wfQueryService.getTaskDetailsById(wfContext, tskId);

// Now get the payload
Element rootelement= myTask.getPayloadAsElement();

// parse the payload to get the required information.
NodeList nl= rootelement.getElementsByTagName("Information");
Node fstnode= nl.item(0);
Element fstElmnt = (Element) fstnode;
NodeList tstNmElmntLst = fstElmnt.getElementsByTagName("Id");
Element tstNmElmnt = (Element) tstNmElmntLst.item(0);
String Id = tstNmElmnt.getFirstChild().getNodeValue();
NodeList tstNmElmntLst1 = fstElmnt.getElementsByTagName("po");
Element tstNmElmnt1 = (Element) tstNmElmntLst.item(0);
String po = tstNmElmnt1.getFirstChild().getNodeValue();
context.getExternalContext().getRequestMap().put("Id", Id);
context.getExternalContext().getRequestMap().put("po", po);

Sunday, January 22, 2012

Why you may get weblogic-application.xml load error for ADF 11g R2 release

If you are getting a below given error when trying to run the ADF application in 11g R2 Jdev release, in integrated weblogic server:


<Unable to load descriptor C:\Jdev\xxx\................/weblogic-application.xml of module AnApp. The error is weblogic.descriptor.DescriptorException: Unmarshaller failed


Goto Application resources tab in your Jdev Application Navigator and open weblogic-application.xml. Check for the duplicate entries in the xml file for the lib refs. Remove all the duplicate entries and try running it again.


This should work, to remove the above mentioned error.

Thursday, January 19, 2012

Using RIDC lib to checkin file into UCM from ADF application.


       Below given code snippet shows, checking in file into UCM repository from ADF application    
       using RIDC lib to . So if you are not using Webcenter, and do not have an access to OOTB  
        taskflow for file upload , this code can help you.


       // Get the file using the file upload component in ADF
       UploadedFile newFile = (UploadedFile)getIf1().getValue();

        // store the file in a temporary location on server
        String tempFold = "C:/tempFold/";
        String fileName =  newFile.getFilename();
        String filetype =  newFile.getContentType();
        InputStream is = null;
        try {
            is = newFile.getInputStream();
            File f= new File(tempFold + fileName);
            OutputStream out=new FileOutputStream(f);
            byte buf[]=new byte[1024];
            int len;
            while((len=is.read(buf))>0)
            out.write(buf,0,len);
            out.close();
            is.close();
        } catch (IOException e) {
        }
       
        // Get Ridc client manager
        IdcClientManager manager = new IdcClientManager();
        IdcClient idcClient = null;
       
        try {
              // create the client to check in the file in the ucm
              idcClient = manager.createClient(<UCM url as string>);
              IdcContext userContext = new IdcContext("weblogic", "welcome1");    
              DataBinder binder = idcClient.createBinder();

              binder.putLocal ("IdcService", "CHECKIN_UNIVERSAL");
              // get the binder
             
              binder.putLocal ("dDocTitle", "File1");
              binder.putLocal ("dDocName", "Despicableme");
              binder.putLocal ("dDocType", "DigitalMedia");
              binder.putLocal ("dSecurityGroup", "Public");
              // add a file
           
              binder.addFile ("primaryFile", new TransferFile( new java.io.File(tempFold + fileName)));
              // checkin the file
              ServiceResponse response = idcClient.sendRequest(userContext, binder);
              // get the response as a string
              String responseString = response.getResponseAsString ();
           
              System.out.println("done");
              System.out.println("st:"+responseString);
        } catch (IdcClientException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
          }