Thursday, September 7, 2017

How To: Launch a popup programmatically (ADF)

Create a binding for the popUp in the backing bean and use the following snippet to launch it programmatically






Hope you find this helpful! Please share your feedback below.

CaptiveCode


Monday, September 4, 2017

How To: Access one managed bean from another (ADF, JSF)

It is a common requirement to access methods between managed beans defined in varied scopes within ADF. In this post, I am invoking backing bean (method to enable/disable a button) from a request bean. The similar approach can be used for other scopes viz. pageFlow, session, application.


Download Sample Code on GitHub


Define your managed beans in your task flow:
    <managed-bean id="__1">
      <managed-bean-name id="__243">RequestBean</managed-bean-name>
      <managed-bean-class id="__244">ui.bean.RequestBean</managed-bean-class>
      <managed-bean-scope id="__245">request</managed-bean-scope>
    </managed-bean>
    <managed-bean id="__2">
      <managed-bean-name id="__248">BackingBean</managed-bean-name>
      <managed-bean-class id="__246">ui.bean.BackingBean</managed-bean-class>
      <managed-bean-scope id="__247">backingBean</managed-bean-scope>
    </managed-bean>
BackingBean Definition:
package ui.bean;

import oracle.adf.view.rich.component.rich.nav.RichCommandToolbarButton;

public class BackingBean {
    private RichButton submitBtn;

    public void setSubmitBtn(RichButton submitBtn) {
        this.submitBtn = submitBtn;
    }

    public RichButton getSubmitBtn() {
        return submitBtn;
    }
}
RequestBean Definition:
package ui.bean;

import javax.el.ELContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

public class RequestBean {

    public BackingBean getBackingBean() {
        FacesContext fctx = FacesContext.getCurrentInstance();
        ELContext context = fctx.getELContext();
        BackingBean backingBean =
            (BackingBean) fctx.getApplication().getExpressionFactory()
                .createValueExpression(context,"#{backingBeanScope.BackingBean}",BackingBean.class)
                .getValue(context);
        return backingBean;
    }

    public void enableSubmit(ActionEvent actionEvent) {
        /* Invoke BackingBean method to enable/disable Submit Button */
        getBackingBean().getSubmitBtn().setDisabled(false);
    }
}



Hope you find this helpful! Please share your feedback below.

CaptiveCode


How To: Execute View Criteria programmatically

Consider the following view criteria is defined on a view object:




To execute this view criteria programmatically, write the following method in the AMImpl class:
    public void executeInvoiceVOCriteria(String invoiceNum, String poNum){
        ViewObjectImpl vo = getInvoiceVO1();        
        ViewCriteria vc = vo.getViewCriteria("InvoiceVOCriteria");
        vo.applyViewCriteria(vc);
        vo.setNamedWhereClauseParam("p_inv_num", invoiceNum);
        vo.setNamedWhereClauseParam("p_po_num", poNum);
        vo.executeQuery();
    }




Hope you find this helpful! Please share your feedback below.

CaptiveCode


Sunday, September 3, 2017

How To: Pass parameters to action listener in ADF

I have commonly come across the requirement to pass parameters to the managed bean method on a button click. The challenge we normally face here is that, the methods attached to the "action" or "actionListener" have fixed signatures that cannot be changed.

Thus, we have to leverage the "<f:attribute>" tag alongwith a "actionListener"


Hope you find this helpful! Please share your feedback below.
CaptiveCode


How To: Throw an exception in ADF

To show an exception on ADF UI, implement the following in your managed bean:




Hope you find this helpful! Please share your feedback below.

CaptiveCode


Saturday, March 25, 2017

How To: Deploying applications on WebLogic using command line

This article is a quick reference on how to deploy applications to WebLogic server using command line interface.

Set classpath as follows:
set CLASSPATH=C:\Weblogic\Middleware\wlserver_10.3\server\lib\weblogic.jar


To deploy from your local desktop (remote):


To deploy a WAR file:
java weblogic.Deployer -adminurl <<admin server host:port>> -user weblogic -password ulorcl123$ -deploy C:\JDeveloper\mywork\myApp\deploy\myApp.war -remote -upload
To redeploy a WAR file:
java weblogic.Deployer -adminurl <<admin server host:port>> -user weblogic -password ulorcl123$ -redeploy -source C:\JDeveloper\mywork\myApp\deploy\myApp.war -remote -upload -name myApp.war


Common Errors:


Error:
'ModuleArchive' cannot be null
Resolution:
Make sure the source parameter is specified in the redeploy command

Hope you find this helpful! Please share your feedback below.
CaptiveCode


Saturday, January 21, 2017

TopLink - Common Errors - ClassCastException

Are you facing a class cast exception while using Oracle TopLink?
For example - com.entity.Organization cannot be cast to com.entity.Organization

In my experience, this issue occurred sporadically and was not consistent. The reason this occurs is because multiple instances of Entity Manager have been created in your application session. The class loader is hence unable to determine the instance of the class that is to be loaded

Here is how I was able to workaround the issue:

  • Create a listener class (myListner) as shown below
    • Override the contextInitialized method to create an entity manager as soon as the application session is initiated
    • Override the contextDestroyed method to release the entity manager as soon as the application session ends
  • This will ensure only a single instance of entity manager exists at any point in time. Thus, eliminating the root cause.


package com.db.dao;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class myListener implements ServletContextListener {
    private static String persistenceUnitName = "Persistent_Unit_Name";
    private static EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnitName);

    public myListener() {
    }

    @Override
    public void contextInitialized(ServletContextEvent event) {
        if (!emf.isOpen()) {
            emf = Persistence.createEntityManagerFactory(persistenceUnitName);
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
        if (emf != null) {
            emf.close();
        }
    }

}

  • Register the listener class in your web.xml
<web-app version="2.5" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xmlns="http://java.sun.com/xml/ns/javaee" 
   xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
  <display-name>myTopLinkProject</display-name>
  <description>Sample TopLink Application</description>
  <filter>
    <filter-name>JpsFilter</filter-name>
    <filter-class>oracle.security.jps.ee.http.JpsFilter</filter-class>
    <init-param>
      <param-name>enable.anonymous</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>JpsFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
  </filter-mapping>
  <listener>
    <description>Web Application Listener</description>
    <display-name>myListener</display-name>
    <listener-class>ul.iam.db.dao.myListener</listener-class>
  </listener>
</web-app>





Hope you find this helpful! Please share your feedback below.

CaptiveCode


How To: Configure JTA Data Source in TopLink persistence.xml

Here is an example of a persistence.xml when using a data source:

<persistence version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xmlns="http://java.sun.com/xml/ns/persistence" 
   xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="Sample" transaction-type="JTA">
    <description>Attribute Data Store</description>
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/SampleDataSource</jta-data-source>
    <properties>
      <property name="toplink.logging.level" value="INFO">
    </property></properties>
  </persistence-unit>
</persistence>





Please share your feedback below. Hope you find this helpful!

CaptiveCode