Thursday, 27 September 2012

simple XMLHttpRequest example with jsps


1)The bellow given is the jsp page where i am using xmlhttprequest to retrive the header information and a text file in the application asynchronously
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc(url)//the parameter url for our resource
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();//creating a new object for ajax
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");//creating a new object for ajax
  }
xmlhttp.onreadystatechange=function()//Stores a function (or the name of a function) to be called //automatically each time the readyState property changes
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)//if status is succes and request is processed
    {
    document.getElementById('p1').innerHTML=xmlhttp.getAllResponseHeaders();//getting all response data
alert(xmlhttp.getResponseHeader('Content-Type'));//getting specific response data
alert(xmlhttp.responseText);
    }
  }
xmlhttp.open("GET",url,true);//it is making a get request with our url asynchronously
xmlhttp.send();
}
</script>
</head>
<body>

<p id="p1">The getAllResponseHeaders() //function returns the header information of a resource, like length, server-type, content-type, last-modified, etc.</p>
<button onclick="loadXMLDoc('xmlhttp_info.txt')">Get header information</button>//here is our onclick function
</body>
</html>







2)xmlhttp_info.txt this file should be in the context path of the application
3)in web.xml welcome file lis tyou should mention the jsp name

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>groupsPrac</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>deskto.jsp</welcome-file>//mention name of your jsp
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

Wednesday, 12 September 2012

Simple tutorial on sap business objects


Simple tutorial on sap business objects

This document is the API specification for the BusinessObjects Enterprise Java SDK.
The BusinessObjects Enterprise Java SDK is a Software Development Kit that provides you with the tools for building scalable web applications. These applications can be divided into two categories: applications that allow users to perform client tasks, such as viewing, scheduling, and exporting reports, and applications that enable administrators to perform administrative tasks, such as managing servers, creating user and groups, gathering metrics, and handling security.
Client tasks
The BusinessObjects Enterprise Java SDK provides you with the tools and components to design a client desktop with the following functionality:
  • logging on to a database
  • maintaining inboxes
  • organizing folders and categories
  • previewing reports using thumbnails
  • viewing reports
  • searching for reports
  • setting parameters for and applying filters to reports
  • scheduling reports with events
  • scheduling reports to a destination
  • exporting reports to a common format
Administrative tasks
The BusinessObjects Enterprise SDK allows you to create your own management tools-- ones that can perform administrative tasks such as the following:
  • adding and modifying user accounts
  • managing groups membership
  • applying report processing extensions
  • assigning security rights
  • setting server properties
  • auditing licenses and viewing system metrics
 The apis commonly used in project:-
com.crystaldecisions.sdk.occa.security This package contains interfaces that allow you to interact with the security session.


In this we use interface to create tokens:-
ILogonTokenMgr This object manages the creation and release of logon tokens for logged on users.
 IUserInfo This is an interface through which user information can be extracted from the security session and then modified.
                             The above interface is used in the following way
                              IUserInfo userInfo = enterpriseSession.getUserInfo();
                             This method of the above interface is used in project
                              java.util.Locale getPreferredViewingLocale()
                               Returns the user's preferred viewing locale.
com.crystaldecisions.sdk.occa.infostore This package provides the ability to query for InfoObjects, as well as add, delete, and update them.
   In the above package we use following class:-         
  IInfoStore IInfoStore represents the BusinessObjects Enterprise InfoStore service.   
Methods    
 IInfoObjects query(java.lang.String query)
           Executes a query against the CMS.  IInfoObjects[]      query(java.lang.String[] queries)
           Executes queries against the CMS.      
com.crystaldecisions.sdk.framework This package implements the highest object model that branches off to the individual library implementations.
Inside the above package we are using following classes in our project:-
CrystalEnterprise The CrystalEnterprise class is the starting point for BusinessObjects Enterprise.
In this class we use  CrystalEnterprise.getSessionMgr();
static ISessionMgr getSessionMgr()
           Returns the singleton
ISessionMgr object.
IEnterpriseSession IEnterpriseSession is the first object to be acquired. It precedes the creation of any other Enterprise components. It combines both the name service and the client-side security objects, and also provides the Service property that makes it possible for users to retrieve the object that gives them access to services on the CMS machine.
 In this class we use following method s
getSerializedSession()Gets a string of a serialized session
 java.lang.String[] getServerNames() Returns a list of available servers.    
 
java.lang.Object  getService(java.lang.String ServiceName)
           Returns an object to use a specific service exposed by the enterprise framework.
 java.lang.Object getService(java.lang.String ServerName, java.lang.String ServiceName)
           Returns an object to use a specific service exposed by a server.
 java.lang.String[] getServiceNames(java.lang.String ServerName, int type)   Returns a list of available services on a particular server.   IUserInfo getUserInfo() Retrieves the UserInfo object, which has information about the user who created the session.
ISessionMgr This is the basic, top level client side object. which includes the methods that must be called when a user attempts to access the BusinessObjects Enterprise system.
In this class we use following methods in our project
IEnterpriseSession logon(org.ietf.jgss.GSSCredential UserCreds, org.ietf.jgss.GSSManager Manager, java.lang.String CMSName, java.lang.String Authentication)
           Logs on to the specified CMS or Cluster.  
IEnterpriseSession logon(java.security.Principal principal)
           Logs on to the CMS using the principal.  
IEnterpriseSession logon(java.lang.String UserName, java.lang.String Password, java.lang.String CMSName, java.lang.String Authentication)
           Logs on to the specified CMS or Cluster.
 ITrustedPrincipal createTrustedPrincipal(java.lang.String userName, java.lang.String cmsName)
           Creates a new ITrustedPrincipal trusted principal object.  ITrustedPrincipal createTrustedPrincipal(java.lang.String userName, java.lang.String cmsName, java.lang.String sharedSecret)
           Creates a new ITrustedPrincipal object.
com.crystaldecisions.sdk.exception This package defines the exceptions thrown by BusinessObjects Enterprise.

The process of login in  business objects:-
  1. Set the user name and password for the Administrator account. This uses the default values that were created when BusinessObjects Enterprise was installed.
 String user = "Administrator"; String password = "";
  1. Set the name of the CMS to log on to.
    String cmsName = "CMS"; 
  1. Set the authentication method to be used and initialize a variable to store any exceptions thrown.
  String cmsAuthType = "secEnterprise";   
    SDKException failure = null;  
 
  1. Log on to the CMS using the specified values. If the logon is successful, the Enterprise session will be retrieved.
    try
    {
        es = CrystalEnterprise.getSessionMgr().logon(
                user,
                password,
                cmsName,
                cmsAuthType);
    }
 
  1. Catch the exception thrown if the logon process failed.
    catch (SDKException error)
   {
        failure = error;
    }
   
  1. Display an error message if the logon failed.
    if (failure != null)
    {       
        out.println(failure);
    }
 
  1. Otherwise, if the logon was successful, set the enterprise session so that it can be retrieved later.
    else
    {
        session.setAttribute("CE_Session", es);
    }
   
  1. Retrieve the InfoStore from the Enterprise session.
    IInfoStore iStore = (IInfoStore) es.getService("", "InfoStore");
  ]
Simple example for login authentication using BO:-

login.jsp

This page is opened when the user clicks Login in the form LoginForm described on 19. The user name and password used for the login are passed from the HTML form in the query string parameters Name and Pass.
<%@ page import="com.crystaldecisions.sdk.framework.CrystalEnterprise" %>
<%@ page import="com.crystaldecisions.sdk.framework.IEnterpriseSession" %>
<%@ page import="com.crystaldecisions.sdk.framework.ISessionMgr" %>
<%@ page import="com.crystaldecisions.sdk.exception.SDKException" %>
<%@  page import="com.businessobjects.rebean.wi.*" %>

<%   String CMS = request.getParameter("CMS");
    String userID = request.getParameter("Name");
    String password = request.getParameter("pass");
    String auth = request.getParameter("auth");
    if ( CMS == null) CMS = "";
    if ( userID == null) userID = "";
    if ( password == null) password = "";
    if ( auth == null) auth = "";

   IEnterpriseSession enterpriseSession;
    try
    {
        ISessionMgr mySessionMgr = CrystalEnterprise.getSessionMgr();

        enterpriseSession =   mySessionMgr.logon(userID, password, CMS,auth);

        if (enterpriseSession != null)
            session.setAttribute("EnterpriseSession",enterpriseSession);
            IInfoStore iStore = (IInfoStore) enterpriseSession.getService("InfoStore");
            session.setAttribute("InfoStore", iStore);
             response.sendRedirect("home.html");
        }
        Else   response.sendRedirect("index.jsp");
    }

    catch( SDKException mySDKExept)
    {
     response.sendRedirect("index.jsp");
    }
%>

Monday, 10 September 2012

dojox datagrid doesn't store last entered value without clicking enter


solves the problem of dojox datagrid doesn't store last entered value without clicking enter

 //include tis method after defining your data grid (it will work in all browzers)
grid.onMouseOut=function()
{

var cells = dojo.query('#'+grid.id+' .dojoxGridCell');
grid.doclick(cells[0]);

}

Sunday, 9 September 2012

example for editable dojox datagrid with hidden column


Sample example for editable datagrid with hidden column(In this example you can set your preferences)

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html >
<head>
<link rel="stylesheet" href="<%=request.getContextPath() +
"/dojo1.4.3/dijit/themes/tundra/tundra.css"%>" type="text/css">
<link rel="stylesheet" href="<%=request.getContextPath() + "/dojo1.4.3/dojox/grid/resources/Grid.css"%>" />
<link rel="stylesheet" href="<%=request.getContextPath() + "/dojo1.4.3/dojox/grid/resources/tundraGrid.css"%>" />

</head>
<body class="tundra landing">
<div id="billsGrid" dojoType="dojox.grid.DataGrid"  escapeHTMLInData="false">
            </div>
           
<input type="button" value="getValues" onclick="xy()">           
</body>
<script language="JavaScript" src="<%=request.getContextPath() +
"/dojo1.4.3/dojo/dojo.js"%>" djconfig="parseOnLoad:true"></script>
<script>
dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dojox.grid.cells.dijit");
dojo.parser.parse();

     itemData={"identifier":"docName",
                  "items":[{"docSelection":false,"docName":"salary","displayName":"salary_sheet","docId":"Fh23r"},
                            {"docSelection":false,"docName":"income","displayName":"income_sheet","docId":"Fs23r"},
                            {"docSelection":false,"docName":"sales","displayName":"sales_sheet","docId":"Ft23r"}]};
   for(var i=0;i<itemData.items.length;i++){
       if(itemData.items[i].docId=="Fs23r"){//check for your preference value
           itemData.items[i].docSelection=true;//dynamically check that check box
           }
       }
    var layout = [ {
        "field" : "docSelection",
        "name" : "Select Reports",
        "width" : "80px",
        editable:true,
        type: dojox.grid.cells.CheckBox,styles: 'text-align: center;'
    }, {
        "field" : "docName",
        "name" : "DocName",
        "width" : "auto"
    } , {
        "field" : "displayName",
        "name" : "DisplayName",
        "width" : "auto",
        editable:true
    }, {
        "field" : "docId",
        "name" : "DocId",
        "width" : "auto",
        hidden:true
    }];
   
     dataStore = new dojo.data.ItemFileWriteStore(
            { data:itemData }
        );
              
        var grid = dijit.byId("billsGrid"); // data grid id
        grid.setStructure(layout); // setting physical structure
        grid.setStore(dataStore);   // setting the data
      
          
//here you can set your preferences after user edits the grid and click the button
 function xy(){alert("hai");
 for(var i=0;i<grid.store._arrayOfAllItems.length;i++){
     if(grid.store._arrayOfAllItems[i].docSelection=="true"){//get only which are checked and store them
          alert(grid.store._arrayOfAllItems[i].docId);
           if(grid.store._arrayOfAllItems[i].displayName!=""){}
           else{alert("diaplay name of selected reports cant be empty");}//validation for display name
         }
     }
 }         
</script>

</html>

Simplest editable dojox datagrid


Simplest editable dojox datagrid (where you can edit displayName attribute and checkbox cor select reports)

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html >
<head>
<link rel="stylesheet" href="<%=request.getContextPath() +
"/dojo1.4.3/dijit/themes/tundra/tundra.css"%>" type="text/css">
<link rel="stylesheet" href="<%=request.getContextPath() + "/dojo1.4.3/dojox/grid/resources/Grid.css"%>" />
<link rel="stylesheet" href="<%=request.getContextPath() + "/dojo1.4.3/dojox/grid/resources/tundraGrid.css"%>" />

</head>
<body class="tundra landing">
<div id="billsGrid" dojoType="dojox.grid.DataGrid"  escapeHTMLInData="false">
            </div>
</body>
<script language="JavaScript" src="<%=request.getContextPath() +
"/dojo1.4.3/dojo/dojo.js"%>" djconfig="parseOnLoad:true"></script>
<script>
dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dojox.grid.cells.dijit");//do not forget this
dojo.parser.parse();

    var itemData={"identifier":"docName",
                  "items":[{"docId":false,"docName":"salary","displayName":"salary_sheet"},
                            {"docId":false,"docName":"income","displayName":"income_sheet"}]};

    var layout = [ {
        "field" : "docId",
        "name" : "Select Reports",
        "width" : "80px",
        editable:true,
        type: dojox.grid.cells.CheckBox,styles: 'text-align: center;'//here we are using checkbox
    }, {
        "field" : "docName",
        "name" : "DocName",
        "width" : "auto"
    } , {
        "field" : "displayName",
        "name" : "DisplayName",
        "width" : "auto",
        editable:true//you have to set this attribute then only it will be editable
    }];
  
    var dataStore = new dojo.data.ItemFileWriteStore(
            { data:itemData }//you have to use writestore for editable datagrids
        );
        var grid = dijit.byId("billsGrid"); // data grid id
        grid.setStructure(layout); // setting physical structure
        grid.setStore(dataStore);   // setting the data 
</script>

</html>

Custom single threaded java server

 package com.diffengine.csv; import java.io.*; import java.net.*; import java.util.Date; public class Server { public static void main(Str...