Monday, 27 August 2012

Simplest data grid example the best for beginner



<%@ 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>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<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"%>" />

<title>Insert title here</title>
</head>
<body class="tundra landing" >    
         <div id="billsGrid" style="height:400px;  width:200px;" 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 type="text/javascript">
dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.data.ItemFileWriteStore");
dojo.parser.parse();

 itemData={"layout":[{"field":"docId","name":"DocId","width":"auto"},
{"field":"docName","name":"DocName","width":"auto"}],
"identifier":"docId",
"items":[{"docId":"244","docName":"balanceSheet"},
{"docId":"255","docName":"incomeSheet"}]}
         // i will be getting the response as data to be populated in grid        
         var dataStore = new dojo.data.ItemFileReadStore(
                    { data:itemData }
                );
                var grid = dijit.byId("billsGrid"); // data grid id
                grid.setStructure(itemData.layout); // setting physical structure
                grid.setStore(dataStore);   // setting the data  


</script>
</html>

Sunday, 19 August 2012

dojo data grid example

dojo data grid example 



getting student results and showing in grid format 



1)the js file:-

    dojo.xhrGet({
        url : "finalData",// back end servlet
        handleAs : "json",
        timeout : 50000,
        load : function(response, ioArgs) {
            var itemData=eval(response);  // i will be getting the response as data to be populated in grid         
             var dataStore = new dojo.data.ItemFileReadStore(
                        { data:itemData }
                    );
                    var grid = dijit.byId("billsGrid"); // data grid id

                    grid.setStructure(itemData.layout); // setting physical structure
                    grid.setStore(dataStore);   // setting the data   
        },

        error : function(response, ioArgs) {
            console.error("HTTP status code: ", ioArgs.xhr.status);
            return response;
        }
    });



2) the jsp page:-






<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib prefix="struts" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page import="java.util.*"%>
<html>
<head>
<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"%>" />
<script type="text/javascript">
dojo.require("dijit.form.DateTextBox");
dojo.require("dijit.Dialog");
dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.data.ItemFileWriteStore");
</script>
</head>
<body class="tundra landing" >
<table id="quePaper_table">     
         <div id="billsGrid" dojoType="dojox.grid.DataGrid" escapeHTMLInData="false" >// using this id i will be inserting data in js
            </div>

</body>
</html>

3) back end servlet(this servlet will return the json that will be later assigned to the grid in js file)

  InputStream convertToJson(ArrayList<StudentScores> studentResultList) {
        final String methodName = "convertToJson";
        log.entering(methodName);
        Iterator<StudentResultScores> it = studentResultList.iterator();

// here we are constructing the layout that means the table structure example
userid name total
345    krish 100
        JSONObject dataObject = new JSONObject();
        JSONObject layoutObject1 = new JSONObject();
        layoutObject1.put("field","userId");
        layoutObject1.put("name","UserId");
        layoutObject1.put("width","auto");//the grid will expand automatically
        JSONObject layoutObject2 = new JSONObject();
        layoutObject2.put("field","name");
        layoutObject2.put("name","Name");
        layoutObject2.put("width","auto");
        JSONObject layoutObject3 = new JSONObject();
        layoutObject3.put("field","total");
        layoutObject3.put("name","Total");
        layoutObject3.put("width","auto");
        JSONArray layoutArray = new JSONArray();
        layoutArray.add(layoutObject1);
        layoutArray.add(layoutObject2);
        layoutArray.add(layoutObject3);
// here we are constructiong the data inside grid

        JSONArray dataArray = new JSONArray();
        JSONObject innerDataObject=null;
        int i=0;
        while(it.hasNext()){           
            StudentResultScores s = it.next();
            innerDataObject=new JSONObject();
            String a="<a href='javascript:getUserAnswerSheet(";
            String b=")'><u>";
            String c="</u></a>";
            innerDataObject.put("userId",a+s.getUserId()+b+s.getUserId()+c);
            log.info("userId"+s.getUserId());
            innerDataObject.put("name", s.getName());
            log.info("name"+s.getName());
            innerDataObject.put("total", s.getTotalScore());
            log.info("total"+s.getTotalScore());
            TreeMap<String, Integer> scoreMap =s.getCategoryScoreMap();
            Set<String> keys=  scoreMap.keySet();
            log.info("categories"+scoreMap.values());
            //Collection<Integer> g=scoreMap.values();
            Iterator<String> itt = keys.iterator();           
            while(itt.hasNext()){   
                String x=itt.next();
                if(i==0){
                JSONObject layoutObject = new JSONObject();//dyanamic layout consrtuction
                layoutObject.put("field",x);
                layoutObject.put("name",x);
                layoutObject.put("width","auto");
                layoutArray.add(layoutObject);
                }
                innerDataObject.put(x,s.getCategoryScoreMap().get(x));                                               
            }   
        i++;   
            dataArray.add(innerDataObject);
        }
        dataObject.put("items", dataArray);//the content data
        dataObject.put("identifier","userId");// unique id to identify
        dataObject.put("layout",layoutArray);//the layout data
        inputStream = new StringBufferInputStream(dataObject.toString());
        return inputStream;
    }


dojo-slide-show

dojo-slide-show

<script type="text/javascript">
dojo.require("dijit.form.ValidationTextBox");
dojo.require("dojox.validate.regexp");
dojo.require("dojo.parser");
dojo.require("dijit.form.Form");
dojo.require("dijit.form.Button");
dojo.require("dojox.image.SlideShow");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dojo.parser");   
dojo.addOnLoad(function(){
            //Initialize the first SlideShow with an ItemFileReadStore
            dojo.parser.parse(dojo.body());
               var request= {count:5, start:3};
                  var itemNameMap = {imageLargeAttr: "url"};
            var imageItemStore = new dojo.data.ItemFileReadStore({data: {"identifier": "url",
  "items": [
    { url: "./images/performance.jpg"},
    { url: "./images/atech-logo-tagline.jpg"},
    { url: "./images/atech-poweredby.jpg"}
  ]
}});
            dijit.byId('slideshow1').setDataStore(imageItemStore,request, itemNameMap);
});           
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="page">
<tr>
<th></th>
<td align="center">
<div id="slideshow1" dojoType="dojox.image.SlideShow"></div></td>
</tr>
</table>

Displaying the portal selection path (breadcrumb trail)

 Displaying the portal selection path (breadcrumb trail)


<%@ taglib uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.0/portal-fmt" prefix="portal-fmt" %>
<%@ taglib uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.0/portal-navigation" prefix="portal-navigation" %>
<%@ page import="com.ibm.portal.model.NavigationSelectionModelHome" %>
<%@ page import="com.ibm.portal.model.NavigationSelectionModelProvider" %>
<%@ page import="com.ibm.portal.navigation.NavigationSelectionModel" %>
<%@ page import="com.ibm.portal.navigation.NavigationNode" %>
<%@ page import="com.ibm.portal.ModelException" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.NamingException" %>
<%
try{
Context ctx = new InitialContext();
NavigationSelectionModelHome home = (NavigationSelectionModelHome)
ctx.lookup("portal:service/model/NavigationSelectionModel");
if (home != null) {
NavigationSelectionModelProvider provider =
home.getNavigationSelectionModelProvider();
NavigationSelectionModel model =
provider.getNavigationSelectionModel(request, response);
for (java.util.Iterator i = model.iterator(); i.hasNext(); )
{
NavigationNode node = (NavigationNode) i.next();
if (i.hasNext()) {
%>
<a href="<portal-navigation:navigationUrl type=’link’ varname=’<%=node%>’/>">
<portal-fmt:title varname=’<%=node%>’/>
</a>
&gt;
<%
}
else
{
%>
<portal-fmt:title varname=’<%=node%>’/>
<%
}
}
}
}
catch (ModelException mx) {
%>
<p><span style="color:#ff0000">A model exception occured</span></p>
<%
}
catch (NamingException nx) {
%>
<p><span style="color:#ff0000">A naming exception occured</span></p>
<%
}

Friday, 17 August 2012

Dojo-way-of-parsing-feed

dojo.require("dojox.atom.io.model");
        dojo.require("dojox.atom.io.Connection");
            var conn = new dojox.atom.io.Connection();
            var ems="<%=contextPath %>/proxy/https/lc01.atech.com/profiles/atom/profile.do?email=pele@atech.com";
            conn.getFeed(ems,  function(feed){
            kk=feed;
            a=kk.entries;
            a[0].title.value;
        });    

Tuesday, 7 August 2012


############# jsp file #####################
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><%@page
    language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<table >
    <tr>
         <td><input id="firstname" dojoType="dijit.form.ComboBox"
                                 onkeypress="getSuggestion()"
                                searchAttr= "GroupName"/></td>        
    </tr>
</table>


#########this is javascript file#################
    dojo.require("dijit.form.ComboBox");
    dojo.require("dojo.data.ItemFileReadStore");
    dojo.require("dojo.data.ItemFileWriteStore");

getSuggestion:function(){
       var xy = {"items":[{"GroupName":"BuildForgeDB2Install"},
                          {"GroupName":"Cert Publishers"},
                          {"GroupName":"DB2ADMNS"},
                          {"GroupName":"DB2USERS"},
                          {"GroupName":"Domain Admins"},
                          {"GroupName":"Domain Computers"},
                          {"GroupName":"Domain Controllers"},
                          {"GroupName":"Domain Guests"},
                          {"GroupName":"Domain Users"},
                          {"GroupName":"Enterprise Admins"},
                          {"GroupName":"Group Policy Creator Owners"},
                          {"GroupName":"HelpServicesGroup"},
                          {"GroupName":"MyGroup_Members"},
                          {"GroupName":"RAS and IAS Servers"},
                          {"GroupName":"Schema Admins"},
                          {"GroupName":"TelnetClients"},
                          {"GroupName":"TV"}],
                          "label":"GroupName",
                          "identifier":"GroupName"};
          fileStore=new dojo.data.ItemFileWriteStore({data:xy});
        fileStore.close();
        a=dijit.byId("firstname");
        a.store=fileStore;
                               
     }

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...