Showing posts with label jave. Show all posts
Showing posts with label jave. Show all posts

Wednesday, 15 December 2021

How to resolve error "This installer must be executed using a Java Development Kit (JDK) "but your jdk path" is not a valid JDK." while installing weblogic server

 Hi

Sometimes we face "not a valid jdk" error while installing weblogic server 


to resolve the above error use the following command and wait some time installation process will start shortly 

"C:\Program Files\Java\jdk1.8.0_311\bin\javaw.exe" -jar F:\Software\servers\weblogic\fmw_12.1.3.0.0_wls.jar









Tuesday, 20 March 2018

Set Default Value of selectOneChoice from Bean in ADF 12c

Hello everyone in this post you will see

1  -  Create selectOneChoice manually
2  -  Set default value of selectOneChoice from bean
3  -  Get selected value in bean

for this post i am using jdeveloper 12.2.1.2.0

Lets start

1  -  Create selectOneChoice manually

Steps  1 -  Create new application
Steps  2 -  Create connection
Steps  3 -  Create Department view Object and then a jsf page

Steps  3 -  Click on the source tab of jsf page and then you need to create the af:selectOneChoice manually


Steps  4 -  Select  af:selectOneChoice and drop a af:forEach component on it
Steps  5 -  Then drop f:selectItem on af:forEach



Steps  6 -  Go to the Bindings tab of your jsf page and create a Tree Binding of Department vo


Steps  6 - Select af:forEach then go to properties pallet select Items value form binding and create a variable d



Steps  7 - Select f:selectItem from structure window and go to properties pallet and set the value of
item Label and item Value like following



Now Run your page


2  -  Set default value of selectOneChoice from bean

To set default value of selectOneChoice

Steps  1 -  Create value binding of selectOneChoice with bean and initialize the property in bean with the department id that you want to set as a default value




Now Run your jsf page you will see the Department Name againt Department id 90



3  -  Get selected value in bean

To get the selected Department Id in bean

Steps  1 -  Create valueChangeListener binding of selectOneChoice with bean
Steps  2 -  set autoSubmit =true of selectOneChoice




Run your page change the value of selectOneChoice



Friday, 10 February 2017

Login With Database Users Dynamically in ADF OR How to Support Dynamic JDBC CREDENTIALS IN ADF

Hi everyone this post is about how you can perform login by using DB level user name and password..
(DB level users also known as  DB level Schema  like HR Schema or SCOTT Schema)

To read more detail click Here
For this example i am using jdeveloper 11.1.2.3.0

Lets start

1) Create a simple Application , connect to Database ( i have contacted with hr schema) create  DepartmentsView VO and  create two jsf pages   ( i ) Login.jsf  ( ii ) Home.jsf

2) On Login.jsf page drag and drop two input text fields and one button to perform login and drope DepartmentsView VO on Home page





3) Now create a request scope been name as Login , create a login() method and bind it to button of login page, to verify user name and password and  to set user name and password in Global variables (Later we use these Global variables for login in  doFilter() method of ADFBindingFilter  Servlet )

Note :- this Login been will only used to verify the user name and password , to set user name and password in Global variables and  to perform logout

Here is the code to of Login been 

package view;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.faces.application.FacesMessage;
import javax.faces.application.ViewHandler;
import javax.faces.component.UIViewRoot;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;

public class Login {
    private String uname;
    private String upw;

        //varify user name and password , set session scope values 
    public Login() {
    }

    public String login() {
        
        if(null != this.uname && null!=this.upw){
                
                Connection conn;
                
                    //set user name and password in session scope variables 
                    FacesContext ctx = FacesContext.getCurrentInstance();
                    HttpSession session = (HttpSession) ctx.getExternalContext().getSession(true);
                    session.setAttribute("uName", this.uname.toUpperCase());
                    session.setAttribute("uPassword", this.upw.toUpperCase());
                   
                   //to varify user name and password 
                try {
                conn = this.getConnection();
                   
        
                    String page="http://127.0.0.1:7101/dye_planing-ViewController-context-root/faces/home.jsf";
                  this.launchNewPage(page);
                    
                   //to refresh the page
                   
                   FacesContext fc = FacesContext.getCurrentInstance();
                         String refreshpage = fc.getViewRoot().getViewId();
                   ViewHandler ViewH =
                   fc.getApplication().getViewHandler();
                         UIViewRoot UIV = ViewH.createView(fc,refreshpage);
                         UIV.setViewId(refreshpage);
                         fc.setViewRoot(UIV);

                
                }
                catch (SQLException e) {
               FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Wrong ID or Password..!"));
                }
                    
                    
            }else
        {
                     FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Please Enter User Name and Password..!"));
                 }
        return null;
        
      
    }
    
    
    
    //to varify the user name and password 
    public  Connection getConnection() throws SQLException {
        String username = this.uname.toUpperCase();
        String password = this.upw.toUpperCase();
        String thinConn = "jdbc:oracle:thin:@ your system or server ip : your port address :mis";
        DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
        Connection conn = DriverManager.getConnection(thinConn, username, password);
        conn.setAutoCommit(false);
        return conn;
    }
    
    
    
    //to perform logout
    public String onLogout(){  
         FacesContext fctx = FacesContext.getCurrentInstance();  
         ExternalContext ectx = fctx.getExternalContext();  
         //String url = ectx.getRequestContextPath() + "/adfAuthentication?logout=true&end_url=/faces/Login.jspx";  
         String page="http://127.0.0.1:7101/dye_planing-ViewController-context-root/faces/ULogin.jsf";
         this.launchNewPage(page);
           
         HttpSession session = (HttpSession)ectx.getSession(false);  
         session.invalidate();  
           
         return null;  
       }  
    
   

//method to luch new pages 
    public void launchNewPage(String p) {
        String newPage = p;
        FacesContext ctx = FacesContext.getCurrentInstance();
        ExtendedRenderKitService erks = Service.getService(ctx.getRenderKit(), ExtendedRenderKitService.class);
        String url = "window.open('" + newPage + "','_self');";
        erks.addScript(FacesContext.getCurrentInstance(), url);
    }
    
    //method to get gat values from expression
    public static Object getEL(String el) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ELContext elContext = facesContext.getELContext();
        ExpressionFactory expressionFactory =
        facesContext.getApplication().getExpressionFactory();
        ValueExpression exp =
        expressionFactory.createValueExpression(elContext, el,
        Object.class);
         
        return exp.getValue(elContext);
        }
         //method to set values for expersion 
        public static void setEL(String el, Object val) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ELContext elContext = facesContext.getELContext();
        ExpressionFactory expressionFactory =
        facesContext.getApplication().getExpressionFactory();
        ValueExpression exp =
        expressionFactory.createValueExpression(elContext, el,
        Object.class);
         
        exp.setValue(elContext, val);
        }


    public void setUname(String uname) {
        this.uname = uname;
    }

    public String getUname() {
        return uname;
    }

    public void setUpw(String upw) {
        this.upw = upw;
    }

    public String getUpw() {
        return upw;
    }
}


4) To support Dynamic JDBC Credentials in adf we need to override the doFilter() method of oracle.adf.model.servlet.ADFBindingFilter  Servlet

this ADF Binding Filter is a servlet filter  that is used to sets up the binding context for the ADF application

this filter is fired and request for application module instance before any page is displayed to the end user. But we need to provide user name and password at run time so we need to display a login page to the end user where they can enter user name and password
so we need to override the doFilter() method to perform run time login

to override this method we also need to add "BC4j Client" library in ViewController
to add this edit the ViewController project's properties and add this library..

to override the method  create a java class in ViewController project  name as DynamicJDBCFilter and and exteds ADFBindingFilter


Here is the complete code

package view;

import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import oracle.adf.model.servlet.ADFBindingFilter;
import oracle.jbo.JboException;
import oracle.jbo.client.Configuration;

public class DynamicJDBCFilter extends ADFBindingFilter{
 
    public DynamicJDBCFilter()
      {
      }

      public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
      {
        HttpSession session = ((HttpServletRequest) request).getSession(false);
        if (session != null && session.getAttribute("loggedin") == null)
        {
        System.out.println("i am in doFilter method.........");

          String usrName = (String) session.getAttribute("uName");
          String pswd = (String) session.getAttribute("uPassword");
     
     
        System.out.println("the uname is        "+usrName);
        System.out.println("the pw is             "+pswd);

          if (usrName != null && session.getAttribute("loggedin") == null)
          {
            try
            {
              if (usrName == null || usrName.length() == 0 ||  pswd == null || pswd.length() == 0)
              {
                throw new JboException("Blank User name or Password");
              }

              session.setAttribute(Configuration.DB_USERNAME_PROPERTY, usrName);
              session.setAttribute(Configuration.DB_PASSWORD_PROPERTY, pswd);
              super.doFilter(request, response, chain);
              session.setAttribute("loggedin", "loggedin");
            }
            catch (oracle.jbo.JboException e)
            {
              try
              {
                session.setAttribute("loggedin", null);
                session.invalidate();
              }
              catch (Exception e2)
              {
              }
              request.getRequestDispatcher("/faces/login.jspx").forward(request, response);
            }
          }
          else
          {
            super.doFilter(request, response, chain);
          }
        }
        else
        {
          super.doFilter(request, response, chain);
        }
      }
}

5) Modify web.xml file

we need to update filters and filter Mapings , to update Filter open web.xml file , click on Filter tab
and update or add adfBindings  and filter Mappings  like the following ...




i have added this statement System.out.println("i am in doFilter method.........");
in DynamicJDBCFilter  class..
now Right click on Login.jsf page and click on Run , the above statement should print on console



until now your application can connect to database ... but for ADF Business Components we need to do the following steps

6 ) ADF Business Components need to connect to the current user at run time , So for this ADF Business components uses oracle.jbo.common.ampool.EnvInfoProvider interface . This interface will invoked by ADF Business Components at run time when it is necessary to connect AM instance to DB.

to implement this interface create a new java class and implement oracle.jbo.common.ampool.EnvInfoProvider ....

The operations declared by the EnvInfoProvider interface are all invoked at different points in the AM creation / connection life cycle by the ADF Bussiness Components at run time.

But we implement getInfo method , because it is used to connect ADF Business Components at run time

Here is the complete code

package view;
import java.util.Hashtable;
import oracle.jbo.common.ampool.EnvInfoProvider;
import oracle.jbo.client.Configuration;

public class DynamicEnvInfoProvider implements EnvInfoProvider  {
 
    private final String un;
      private final String upw;

      public DynamicEnvInfoProvider(String uname, String upassword)              
      {
         un = uname;
         upw = upassword;
      }

      public Object getInfo(String info, Object connEnvironment)
      {
        if(un != null)                                                              
        {
          ((Hashtable)connEnvironment).put(Configuration.DB_USERNAME_PROPERTY, un);
        }
        if(upw != null)                                                            
        {
          ((Hashtable)connEnvironment).put(Configuration.DB_PASSWORD_PROPERTY, upw);
        }
        return null;                                                                          
      }

      public void modifyInitialContext(Object p0)
      {
      }

      public int getNumOfRetries()
      {
        return 0;
      }
}

7 ) Reference this DynamicEnvInfoProvider

To uniquely identify every session in application pool , the Application Pool use oracle.jbo.common.ampool.SessionCookie  class . So , every HTTP request that requires AM instance from Application pool will create a Session Cookie and remains live until the session ended. At run time this Session Cookie instance will reuse every time when ever the session requires an AM instance from application pool.

to connect the ADF Business Components with session ,an  object of  EnvInfoProvider   save in Session Cookie

ADF Business Components API provides the SessionCookie.setEnvInfoProvider (EnvInfoProvider) method to store a reference of EnvInfoProiver instance in SessionCookie. The Application Pool also check the existence of EnvInfoProvider instance when AM instance need to connect .

Create SessionCooike Implementation

create a java class in ViewController and extends it with HttpSessionCookieImpl

Here is the complete code

package view;
import oracle.jbo.common.ampool.ApplicationPool;
import oracle.jbo.http.HttpSessionCookieImpl;
import oracle.jbo.common.ampool.EnvInfoProvider;

public class DynamicSessionCookieImpl extends HttpSessionCookieImpl {
 
    public DynamicSessionCookieImpl(java.lang.String applicationId,
        java.lang.String sessionId, ApplicationPool pool)
      {
        super(applicationId, sessionId, pool);
      }

      public DynamicSessionCookieImpl(java.lang.String applicationId,
        java.lang.String sessionId, ApplicationPool pool, java.security.Principal userPrincipal,
        javax.servlet.http.HttpServletRequest request)
      {
        super(applicationId, sessionId, pool, userPrincipal, request);
      }

      public DynamicSessionCookieImpl(java.lang.String applicationId,
        java.lang.String sessionId, ApplicationPool pool, java.security.Principal userPrincipal,
        javax.servlet.http.HttpSession session)
      {
        super(applicationId, sessionId, pool, userPrincipal, session);
      }

      public void setEnvInfoProvider(EnvInfoProvider envInfoProvider)
      {
        if (envInfoProvider != null)
        {
          super.setEnvInfoProvider(envInfoProvider);
        }
      }
}

8 ) Create a Session Cookie Factory

This Session Cookie Factory will use to initialize the new SessionCookies along with EnvInfoProvider instance

create a new java class in ViewController Project and extends it with HttpSessionCookieFactory

Complete code here

package view;
import oracle.jbo.common.ampool.SessionCookie;
import oracle.jbo.common.ampool.ApplicationPool;
import oracle.jbo.common.ampool.EnvInfoProvider;
import java.util.Properties;
import java.util.Hashtable;
import oracle.jbo.http.HttpSessionCookieFactory;
import oracle.jbo.client.Configuration;
import javax.servlet.http.HttpSession;

public class SessionCookieFactory extends HttpSessionCookieFactory {
 
    public SessionCookie createSessionCookie(String name, String value, ApplicationPool pool, Properties properties)
     {
       SessionCookie cookie = super.createSessionCookie(name, value, pool, properties);

       if (properties != null)
       {
         HttpSession session = (HttpSession) properties.get(HTTP_SESSION);
         if (session != null)
         {
           Hashtable env = pool.getEnvironment();
           env.remove(Configuration.DB_USERNAME_PROPERTY);
           env.remove(Configuration.DB_PASSWORD_PROPERTY);
           pool.setUserName(null);
           pool.setPassword(null);
           EnvInfoProvider provider = new DynamicEnvInfoProvider(
               (String) session.getAttribute(Configuration.DB_USERNAME_PROPERTY),
               (String) session.getAttribute(Configuration.DB_PASSWORD_PROPERTY));
           cookie.setEnvInfoProvider(provider);
         }
       }
       return cookie;
     }

     public Class getSessionCookieClass()
     {
       try
       {
         return Class.forName("view.DynamicSessionCookieImpl");// path to DynamicJDBCHttpSessionCookieImpl class
       }
       catch (ClassNotFoundException cnfe)
       {
         cnfe.printStackTrace();
         return null;
       }
     }
}

9 ) AppModule Setting

Finally after creating your own SessionCookieFactory  , to force the Application pool to use this factory instead of default , we need to update the jbo.ampool.SessionCookieFactory property

So open the AM Configurations update the following setting for both

AppModuleShared and
AppModuleLocal



Set connection type to JDBC URL



update jbo.ampool.SessionCookieFactory property




now run your Application , i am connecting with HR Schema , it Will show the data of Department table




Then i create another user as gul and login by using this user name and password




and the out put will be


Thanks







Sunday, 29 May 2016

ADF Business Components Part 1 (Enity Object , View Objects , ApplicationModule )

Hi everyone This is my Second Post part 1, In my First post I simply describe  how you can create your first application by using JDeveloper 11.1.2.3.0, here is the link

http://adfindepth.blogspot.com/2016/05/how-to-start-with-adf.html


Today I'll describe the ADF Business Components (i just give you a basic overview )
ADF Frame Work bases on MVC (Model View Controller ) Model, So
 whenever we start a new Application the ADF Frame Work divide it into two projects
1) Model
2)View + Controller  = View Controller
Here I am just giving you an idea about the Model layer
Model Layer is Simply used to access the data from Database or other sources
Here in the model layer, we can apply simple Validations,  Constraints, and other business logic
We can perform customization (change view objects name, data types, and  so on.....)
Now the question is in ADF in what form we can access data
There is two simple things
1)  Entity Object
2) View Object

Basically, there are three main Main Business Components
1) Entity Object
2) View Object
3) AppModule
And further is
Associations
and View Links

Entity Object  is just the copy of the complete structure of the Database table in ADF 
(Complete Structure means all the attributes, data types, constraints )

For example, you have a table( Table name = Std_tbl) in the database with three attributes
id with data type number and primary key constraints apply on it
second one is name with data type String
and 3rd one is age with data type number
Now when you create an Entity object base on Std_tbl  table , it copies all the attributes with  all its constraints









And in Model Layer you can add more constraints with the help of tool


Secondly ViewObject
There are 4 types of View Objects
1) Entity Base
2) SQL Query base
3) Programmatic base
4) Static List

 View Object that are base on Enity Object are Update able
Means you can perform all type of DML operations on it (insert , delete ,update modify )
And View Object is used to display the data to end user

--> ApplicationModule
It control the data navigation and all connections

Now we create and Application and try to understand about these things
Please Run your jdeveloper click on File Menu and select new
Select Application from left side and Fusion Web Application From right side



Then Click your Application Name and Click next


Now the Next Window is to specify the name of Model Layer and press two time Next 

In Next Window specify the name of ViewController or leave it as default  and press Next , Next and Finsh

So you finally build Application 

Continue..........

url of  Second Part 




Please Feel Free To Ask if you Face any Difficulty 
Like and share to help others
Thanks
Date 29-05-2016







Query to get Business unit (ORGANIZATION_ID) Detail in oracle Fusion

  SELECT HAO.ORGANIZATION_ID AS BUSINESS_UNIT_ID,         HAOT.NAME,         HAO.BUSINESS_GROUP_ID,         HAO.EFFECTIVE_START_DATE,       ...