4 Ekim 2010 Pazartesi

6-taskflows in adf

dewr3

30 Eylül 2010 Perşembe

5-calling stored procedures.and pl/sql functions in adf

in my previous blog i explained exception handling. now i will explain calling stored procedure.

in appmoduleimpl create method that named "addInformationMessageTest" .


public void addInformationMessageTest(String message, String cause)
  {
    DBTransaction trans = getDBTransaction();

    try
    {
      System.out.println("sd" + message);
      String plsql = "BEGIN eklesyslog(?,?,?); END;";

      CallableStatement stmt = trans.createCallableStatement(plsql, 0);
      stmt.setString(3, cause);
      stmt.setString(2, message);
      stmt.setString(1,
                     ADFContext.getCurrent().getSecurityContext().getUserName());
      stmt.execute();
      stmt.close();
      trans.commit();

    }
    catch (SQLException e)
    {
      if (trans != null)
      {
        System.out.println("2");
        trans.rollback();
      }
      System.out.println("23");
      throw new JboException(e);
    }
  }

import oracle.jbo.JboException;
import oracle.jbo.Session;
import oracle.jbo.server.ApplicationModuleImpl;
import oracle.jbo.server.DBTransaction;
import oracle.jbo.server.ViewLinkImpl;
import oracle.jbo.server.ViewObjectImpl;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import oracle.jdbc.OracleTypes;




sample using function
public String BirimArmonizeDegisti(String armonizebirimbir, String armonizebirimiki, String cnbirimbir,
                           String cnbirimiki, String cnnumber)
  {
    CallableStatement cs=null;

    try{

    cs=getDBTransaction().createCallableStatement("begin ? := ISLEM_CARPAN_BUL(?,?,?,?,?); end;",0);

     cs.registerOutParameter(1, Types.VARCHAR);

      cs.setString(6, cnnumber);
      cs.setString(5, cnbirimiki);
      cs.setString(4, cnbirimbir);
      cs.setString(3, armonizebirimiki);
      cs.setString(2, armonizebirimbir);

    cs.executeUpdate();

    return cs.getString(1);

    }catch(SQLException e){

    throw new JboException(e);
    
  }
  }
after this process you wil see this methods in datacontrols section.
drag method your page and use it.
sample using method binding.

BindingContainer bindings = getBindings();
    OperationBinding operationBinding =
      bindings.getOperationBinding("getDataGrupSeviye");
    operationBinding.getParamsMap().put("madde", madde);
    operationBinding.getParamsMap().put("ikili", ikili);
   operationBinding.execute()

29 Eylül 2010 Çarşamba

4-exception handling and logging in adf

create a class and extend it from DCErrorHandlerImpl. overriding getDisplayMessage and reportException enough for exception handling.

package view;

import java.util.Map;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.model.binding.DCErrorHandlerImpl;

import oracle.binding.OperationBinding;


public class CustomErrorHandler extends DCErrorHandlerImpl 
{
    public CustomErrorHandler() 
    {
        super(true);//test
    } 
    @Override
    public String getDisplayMessage(BindingContext ctx, Exception th) 
    {
      FacesContext ctx3 = FacesContext.getCurrentInstance();
      FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_INFO, "Teknik hata", th.getLocalizedMessage());
      ctx3.addMessage(null, fm);
      return super.getDisplayMessage(ctx, th);
    }

    @Override
    public void reportException(DCBindingContainer dCBindingContainer, Exception exception) 
    {
      BindingContext bindingContext = dCBindingContainer.getBindingContext();
      DCBindingContainer templateBindingContainer = bindingContext.findBindingContainer("view_templateMasterPageDef");
      String error = getDisplayMessage(dCBindingContainer.getBindingContext(), exception);
      OperationBinding operationBinding = templateBindingContainer.getOperationBinding("addInformationMessageTest");
      Map params = operationBinding.getParamsMap();
      params.put("cause", exception.getCause());
      params.put("message", exception.getMessage());
      operationBinding.execute();
      //super.reportException(dCBindingContainer, exception);
    }
    /**
     * Local method and not used outside
     * @param warning
     * @return
     */
    
  }






in databinding.cpx




in your masterpage bind method "addInformationMessageTest" to send exception to db or whatever .

i will explain another post using stored procedure and functions in adf.

27 Eylül 2010 Pazartesi

3-adf security. (with ldap and database provider from weblogic)








sample login method like this.

package MBeans;

import java.io.IOException;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import javax.security.auth.Subject;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.FailedLoginException;
import javax.security.auth.login.LoginException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import oracle.adf.model.BindingContext;
import oracle.adf.view.rich.component.rich.input.RichInputText;

import oracle.binding.BindingContainer;

import weblogic.security.SimpleCallbackHandler;
import weblogic.security.services.Authentication;

import weblogic.servlet.security.ServletAuthentication;


public class LoginBean
{
  private RichInputText txtUserName;
  private RichInputText txtPassword;

  public LoginBean()
  {
  }

  public BindingContainer getBindings()
  {
    return BindingContext.getCurrent().getCurrentBindingsEntry();
  }

  public String SubmitLogin_action()
  {
    String un = "";
    String pws = "";
    byte[] pw = null;
    try
    {
      un = (String) txtUserName.getValue();
      pws = (String) txtPassword.getValue();
      pw = pws.getBytes();
    }
    catch (Exception ex)
    {
      System.out.println(ex);
    }


    FacesContext ctx = FacesContext.getCurrentInstance();
    HttpServletRequest request =
      (HttpServletRequest) ctx.getExternalContext().getRequest();
    CallbackHandler handler = new SimpleCallbackHandler(un, pw);
    try
    {
      //login i?lemini ldap üzerinden gerçekle?tiriyor
      Subject mySubject = Authentication.login(handler);
      System.out.println("ldap");
      if (mySubject != null)
      {
        String un1 = un;
        String pwscakma = un;
        byte[] pwcakma = pwscakma.getBytes();
        //login i?lemi ldap üzerinden gerçekle?iyor ise db den roller için bir daha login oluyor
        CallbackHandler handler2 = new SimpleCallbackHandler(un1, pwcakma);
        Subject mySubject2 = Authentication.login(handler2);
        System.out.println("db");
        System.out.println(mySubject.getPrincipals());
        System.out.println(mySubject2.getPrincipals());
        ServletAuthentication.runAs(mySubject2, request);
        ServletAuthentication.generateNewSessionID(request);
        //db den contexte selam

        //BindingContainer bindings = getBindings();
        //OperationBinding operationBinding =
        //bindings.getOperationBinding("setContext");
        //operationBinding.getParamsMap().put("kullaniciad", un1);
        //operationBinding.execute();

        //yönlendiriliyor
        String loginUrl =
          "/adfAuthentication?success_url=/faces/WepPages/Welcome.jspx";
        HttpServletResponse response =
          (HttpServletResponse) ctx.getExternalContext().getResponse();
        sendForward(request, response, loginUrl);
      }
    }
    catch (FailedLoginException fle)
    {
      fle.printStackTrace();
      FacesMessage msg =
        new FacesMessage(FacesMessage.SEVERITY_ERROR, "Yanl?? Kullan?c? ad? veya parola?",
                         "Yanl?? Kullan?c? ad? veya parola");
      ctx.addMessage(null, msg);
    }
    catch (LoginException le)
    {
      reportUnexpectedLoginError("LoginException", le);
    }
    return null;
  }

  private void sendForward(HttpServletRequest request,
                           HttpServletResponse response, String loginUrl)
  {
    FacesContext ctx = FacesContext.getCurrentInstance();
    RequestDispatcher dispatcher = request.getRequestDispatcher(loginUrl);
    try
    {
      dispatcher.forward(request, response);
    }
    catch (ServletException se)
    {

    }
    catch (IOException ie)
    {

    }
    ctx.responseComplete();

  }

  private void reportUnexpectedLoginError(String string, LoginException le)
  {
    FacesMessage msg =
      new FacesMessage(FacesMessage.SEVERITY_ERROR, "Giri? Esnas?nda Beklenmeyen bir hata olu?tu",
                       "Giri? Esnas?nda Beklenmeyen bir hata olu?tu (" +
                       string + "), Detaylar için Loglara bak?n?z");
    FacesContext.getCurrentInstance().addMessage(null, msg);
    le.printStackTrace();

  }

  public void setTxtUserName(RichInputText txtUserName)
  {
    this.txtUserName = txtUserName;
  }

  public RichInputText getTxtUserName()
  {
    return txtUserName;
  }

  public void setTxtPassword(RichInputText txtPassword)
  {
    this.txtPassword = txtPassword;
  }

  public RichInputText getTxtPassword()
  {
    return txtPassword;
  }
}

for using db or ldap or both of them for authantication. you must define provider in weblogic.




here is the some sample usage of security context.

in java

ADFContext.getCurrent().getSecurityContext().getUserName();
ADFContext.getCurrent().getSecurityContext().isUserInRole();

in jspx


2-adf custom css skinning

create a xml file with name "trinidad-skins.xml" in in WEB-INF



register skin name in trinidad-config.xml

create a css file in defined place and use your custom css.


.AFDefaultFontFamily:alias {font-family: Verdana}.AFDefaultFont:alias {font-size: 16px}


use skin selectors.

hope this link helpful for you.

http://jdevadf.oracle.com/adf-richclient-demo/docs/skin-selectors.html

c u next post.

21 Eylül 2010 Salı

1-create pagetemplate, role based dynamic menu,page navigation

after creating template. insert a panelstrechlayout and configure for menu, banner, indicator,etc. we are using pagetemplates for inheritable content and actions. for example banner and menu or username info.


  
  
    
      
        templateMaster
        
          center
          center
        
      
    
    
      
        
          
            
          
                
                
                
                
          
            
          
          
            
          
          
        
      
      
        
          
            
          
        
      
    
  



below code show you; for creation role based menu using MenuBean.initMenu method and for logout dologout.

public class MenuBean
{
      private RichMenuBar initMenu;
  
     public void createMenus(PhaseEvent phaseEvent) 
     {

        // check the menu is already added
        boolean addMenu = true;
        for (Iterator iterator = initMenu.getChildren().iterator(); iterator.hasNext();) {
            UIComponent component = (UIComponent) iterator.next();
            if ( component.getId().startsWith("menuId")){
                addMenu = false;
            }
        } 
        if (addMenu) {

            // get roles
            String[] roles = ADFContext.getCurrent().getSecurityContext().getUserRoles();

            // get application module
            AppModuleImpl menuAM = getAm();
            SysmenuicerikViewImpl menuView = (SysmenuicerikViewImpl)menuAM.getSysmenuicerikView1();
            menuView.executeQuery();
          
            while (menuView.hasNext()) 
            {
           
                SysmenuicerikViewRowImpl menuItem =  (SysmenuicerikViewRowImpl)menuView.next();
                // check if the user has this role
                boolean roleFound = false;
                for (int i = 0 ; i < roles.length ; i++ )
                {
                    if ( roles[i].equalsIgnoreCase(menuItem.getRolaciklama()) )
                    {
                      roleFound = true;  
                    }
                }

                if (roleFound) {
                Boolean menuFound = false;
                RichMenu menu = new RichMenu();
                String menuId = "menuId" + menuItem.getMenukod().toString();

                // check if the main menu is already added
                for (Iterator iterator = initMenu.getChildren().iterator();
                     iterator.hasNext(); ) {
                    UIComponent component = (UIComponent)iterator.next();
                    if (component.getId().equalsIgnoreCase(menuId)) {
                        menuFound = true;
                        menu = (RichMenu)component;
                    }
                }
                if (!menuFound) {
                    // new main menu
                    RichMenu newMenu = new RichMenu();
                    newMenu.setInlineStyle("font-family:Verdana;");
                    newMenu.setId(menuId);
                    newMenu.setText(menuItem.getAnamenuaciklama());
                    newMenu.setIcon(menuItem.getAnamenuikon());
                    initMenu.getChildren().add(newMenu);
                    menu = newMenu;
                }

                Boolean menuItemFound = false;
                String menuItemId = menuItem.getKisayoladi();

                // check if the menu item is already added

                for (Iterator iterator = menu.getChildren().iterator();
                     iterator.hasNext(); ) {
                    UIComponent component = (UIComponent)iterator.next();
                    if (component.getId().equalsIgnoreCase(menuItemId)) {
                        menuItemFound = true;
                    }
                }
                if (!menuItemFound) {
                    RichCommandMenuItem richMenuItem = new RichCommandMenuItem();
                    richMenuItem.setId(menuItemId);
                    richMenuItem.setText(menuItem.getAciklama());
                    richMenuItem.setInlineStyle("font-family:Verdana;");
                    richMenuItem.setActionExpression(getMethodExpression(menuItem.getAction()));
                    richMenuItem.setIcon(menuItem.getIcon());
                    menu.getChildren().add(richMenuItem);
                    
                }
              }
            }
            //menuView.remove();
        }
      }
  
       
      private AppModuleImpl getAm() 
      {
          FacesContext fc = FacesContext.getCurrentInstance();
          Application app = fc.getApplication();
          ExpressionFactory elFactory = app.getExpressionFactory();
          ELContext elContext = fc.getELContext();
          ValueExpression valueExp = elFactory.createValueExpression(elContext, "#{data.AppModuleDataControl.dataProvider}", Object.class);
          return (AppModuleImpl)valueExp.getValue(elContext);
      } 
      private MethodExpression getMethodExpression(String name) 
      {
          Class[] argtypes = new Class[1];
          argtypes[0] = ActionEvent.class;
          FacesContext facesCtx = FacesContext.getCurrentInstance();
          Application app = facesCtx.getApplication();
          ExpressionFactory elFactory = app.getExpressionFactory();
          ELContext elContext = facesCtx.getELContext();
          return elFactory.createMethodExpression(elContext, name, null,
                                                  argtypes);
      }

      public String doLogOut() throws IOException, ServletException
      {
          
          ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();
          HttpServletResponse response = (HttpServletResponse)ectx.getResponse();
          HttpServletRequest request =(HttpServletRequest)ectx.getRequest();
          String url = "/adfAuthentication?logout=true&end_url=/faces/login.jspx";  
          FacesContext ctx = FacesContext.getCurrentInstance();
          RequestDispatcher dispatcher = request.getRequestDispatcher(url);
          try 
          {
           dispatcher.forward(request, response);
          } 
          catch (ServletException se) 
          {
        
          }
          catch (IOException ie) 
          {
           
          }
          ctx.responseComplete();

          return null;
      }
        
   
      public void setInitMenu(RichMenuBar initMenu) 
      {
        this.initMenu = initMenu;
      }

      public RichMenuBar getInitMenu() 
      {
       return initMenu;
      }
}
SysmenuicerikViewImpl is a viewobject and query like that;
SELECT Sysmenuicerik.KOD, 
       Sysmenuicerik.ACIKLAMA, 
       Sysmenuicerik.KISAYOLADI, 
       Sysmenuicerik.SIRA, 
       Sysmenuicerik.ACTION, 
       Sysmenuicerik.MENUKOD, 
       Sysmenuicerik.ICON, 
       Sysmenuicerik.OLUSTURMATARIHI, 
       Sysmenuicerik.OLUSTURAN, 
       Sysmenuicerik.DEGISTIRMETARIHI, 
       Sysmenuicerik.DEGISTIREN,
Sysmenu.ACIKLAMA as AnaMenuACIKLAMA,
Sysrol.ACIKLAMA as RolAciklama,
Sysmenu.ikon as AnaMenuIKON
FROM SYSMENUICERIK Sysmenuicerik, ROLMENUILISKILERI Rolmenuiliskileri, SYSMENU Sysmenu, SYSROL Sysrol
WHERE ((Sysmenuicerik.KOD = Rolmenuiliskileri.MENUICERIKKOD) AND (Sysmenuicerik.MENUKOD = Sysmenu.KOD)) AND (Rolmenuiliskileri.ROLID = Sysrol.KOD) order by Sysmenu.SIRA
here is the sample db scripts
CREATE TABLE SYSROL
(
  KOD               NUMBER(10)                  NOT NULL,
  ACIKLAMA          VARCHAR2(30 BYTE)           NOT NULL,
  OLUSTURMATARIHI   DATE                        DEFAULT SYSDATE,
  OLUSTURAN         VARCHAR2(30 BYTE),
  DEGISTIRMETARIHI  DATE,
  DEGISTIREN        VARCHAR2(30 BYTE)
)

CREATE TABLE SYSMENUICERIK
(
  KOD               NUMBER(10)                  NOT NULL,
  ACIKLAMA          VARCHAR2(30 BYTE)           NOT NULL,
  KISAYOLADI        VARCHAR2(30 BYTE),
  SIRA              NUMBER(2),
  ACTION            VARCHAR2(60 BYTE)           NOT NULL,
  MENUKOD           NUMBER(10)                  NOT NULL,
  ICON              VARCHAR2(60 BYTE),
  OLUSTURMATARIHI   DATE                        DEFAULT SYSDATE,
  OLUSTURAN         VARCHAR2(30 BYTE),
  DEGISTIRMETARIHI  DATE,
  DEGISTIREN        VARCHAR2(30 BYTE)
)

CREATE TABLE SYSMENU
(
  KOD               NUMBER(10)                  NOT NULL,
  ACIKLAMA          VARCHAR2(30 BYTE)           NOT NULL,
  SIRA              NUMBER(2),
  KISAYOLADI        VARCHAR2(30 BYTE),
  IKON              VARCHAR2(60 BYTE),
  OLUSTURMATARIHI   DATE                        DEFAULT SYSDATE,
  OLUSTURAN         VARCHAR2(30 BYTE),
  DEGISTIRMETARIHI  DATE,
  DEGISTIREN        VARCHAR2(30 BYTE)
)

CREATE TABLE ROLMENUILISKILERI
(
  KAYITNO           NUMBER(10),
  ROLID             NUMBER(10)                  NOT NULL,
  MENUICERIKKOD     NUMBER(10)                  NOT NULL,
  OLUSTURMATARIHI   DATE                        DEFAULT SYSDATE,
  OLUSTURAN         VARCHAR2(30 BYTE),
  DEGISTIRMETARIHI  DATE,
  DEGISTIREN        VARCHAR2(30 BYTE)
)



in code

richMenuItem.setActionExpression(getMethodExpression(menuItem.getAction()));

come from SYSMENUICERIK action column. column data look like "VergiOran". in page navigation. this action will be called.

after all procces completed. it works fine. see u next post.

Building an enterprise application step by step with jdeveloper 11g

in this blog i ll try to explain how to build an enterprise application with adf.

in this blog

1-create pagetemplate, role based dynamic menu,page navigation
2-skinning
3-adf security. (with ldap and database provider)
4-exception handling and logging
5-calling stored procedures.
6-taskflows
7-deploy
8-weblogic
9-testing
10-components
11-integration
a-with obiee
b-with webcenter