YUI 2 Popup

Steps

Step 1:

Import the css and javascript files of YUI

<link rel=”stylesheet” type=”text/css” href=”../build/fonts/fonts-min.css” />
<link rel=”stylesheet” type=”text/css” href=”../build/button/assets/skins/sam/button.css” />
<link rel=”stylesheet” type=”text/css” href=”../build/container/assets/skins/sam/container.css” />
<script type=”text/javascript” src=”../build/yahoo-dom-event/yahoo-dom-event.js”></script>
<script type=”text/javascript” src=”../build/connection/connection-min.js”></script>
<script type=”text/javascript” src=”../build/element/element-min.js”></script>
<script type=”text/javascript” src=”../build/button/button-min.js”></script>
<script type=”text/javascript” src=”../build/dragdrop/dragdrop-min.js”></script>
<script type=”text/javascript” src=”../build/container/container-min.js”></script>

Step 2: write the YUI javascript to create a popup

YAHOO.namespace(“ebee.popup”);
YAHOO.util.Event.onDOMReady( function() {
// Define various event handlers for Dialog

var handleSuccess = function(o) {
var response = o.responseText;
};
var handleFailure = function(o) {
alert(“Submission failed: ” + o.status);
};

// Remove progressively enhanced content class, just before creating the
// module
YAHOO.util.Dom.removeClass(“popupdialog”, “yui-pe-content”);

// Instantiate the Dialog
YAHOO.ebee.popup.dialog = new YAHOO.widget.Dialog(“popupdialog”, {
modal :true,
zindex:1000,
visible :false,
fixedcenter:true,
constraintoviewport :true

});
if (!YAHOO.ebee.popup.wait) {

// Initialize the temporary Panel to display while waiting for external content to load

YAHOO.ebee.popup.wait =
new YAHOO.widget.Panel(“wait”,
{ width: “240px”,
fixedcenter: true,
close: false,
draggable: false,
zindex:500,
modal: true,
visible: false
}
);
YAHOO.ebee.popup.wait.setHeader(“Loading, please wait…”);
YAHOO.ebee.popup.wait.setBody(“<img src=\”../images/loading.gif\”/>”);
YAHOO.ebee.popup.wait.render(document.body);

}
// Wire up the success and failure handlers
YAHOO.ebee.popup.dialog.callback = {
success :handleSuccess,
failure :handleFailure
};
// Render the Dialog
YAHOO.ebee.popup.dialog.render();
});

Step 3: we have to apply the yui-skin-sam class to the body of the page
<body class=”yui-skin-sam”>

</body>

Step 2: create a div in the body and give an id (This id is used in the yui widget dialog as shown in step 2) to that and we also create header and body of the popup by defining the div s inside the main div

<div id=”popupdialog“><div class=”hd”></div><div class=”bd”></div></div>

actually this div is used as a popup by yui

Step 3:

jboss 4.0.5 server configration to jdk 6

The jboss 4.0.5 server is supported to jdk 5 features like generics,foreach etc by change the configuration in

\jboss-4.0.5.GA\server\default\deploy\jbossweb-tomcat55.sar\conf\web.xml

uncomment the

<!– Uncomment to use jdk1.5 features in jsp pages
<init-param>
<param-name>compilerSourceVM</param-name>
<param-value>1.5</param-value>
</init-param>
–>

Java Regular Expression to get a sentence between two words

import java.util.regex.*;
import java.util.*;
public class Example{
public static void main(String args[]){
String input = “select col1,col2,col3,col4 from table”;
Pattern p = Pattern.compile(“(?<=\\bselect\\b).*?(?=\\bfrom\\b)”);
Matcher m = p.matcher(input);
List<String> matches = new ArrayList<String>();
while (m.find()) {
matches.add(m.group());
}
for(int i=0;i<matches.size();i++){
System.out.println(“OUTPUT Sentence :”+matches.get(i));
}
}
}

javascript scrollTo(x,y)

Steps:

1.Use this code

function focusElm(elem){
//get y pos
var yPos = elem.offsetTop;
tempEl = elem.offsetParent;
while ( tempEl != null ){
yPos += tempEl.offsetTop;
tempEl = tempEl.offsetParent;
}
//scroll window to y pos
setTimeout(“window.scrollTo(0,”+yPos+”)”,1);
//focus
elem.focus();
}

2.The scrollTo is creating some problems in IE so setTimeout is reqired

Note:we have to call this method in the body onload elseĀ  IE is giving offsetTop zero.

Project Architecture

Project Architecture

*Project Architecture:

Project Architecture means what are the tiers in our project with flow diagram.suppose our project contains five tiers like client tier presentation tier Business tier Integration tier Data tier. then we draw the all tiers flow. project approach is different from project architecture.

* Client tier:

IE Browser (default) from which the end user will access the application. The request from the browser will be submitted to the Application Server using HTTP protocol. The Response from the presentation layer (struts framework) will be interpreted into html pages to view on the browsers.

* Presentation Tier:

Struts Framework with Tiles:-

On Request from the browser the appropriate Action Class handles the user request. The Action class then connects to the business tier via Service Business Delegate.

Tiles have been used to create a set of pages with a consistent user interface (e.g.: the same navigation bar header footer etc.).

Taglibs are used for displaying tabular data (e.g. search results) in a consistent fashion with pagination.

Business Delegate layer:-

Enable the Struts Action classes to be unaware of underlying Session Beans

Encapsulates the invocation of Service Locator to locate them.

Advantages of Struts:-

Centralized File-Based Configuration i.e. rather than hard-coding information into Java programs many Struts values are represented in XML or property files.

This loose coupling means that many changes can be made without modifying or recompiling Java code.

Validation of the user entry fields in the jsps to be handled by entries in the validation.xml and defining validation rules in validator-rules.xml.

Internationalization of the static components of the screen as field and button labels titles error messages etc.

This approach also lets Java and Web developers to focus on their specific tasks (like implementing business logic presenting certain values to clients.) without needing to know about the overall system layout.

* Business Tier:

The Business Delegate identifies the business service class (the Session EJBs) and delegates client request to the EJBs. Internally the session beans are shallow and delegate all business logic requests to business logic POJOs which in turn implement the actual functionality.

The Business Logic POJOs encapsulate the server side business logic. They do not use Hibernate directly but instead call upon Data Access Objects (DAO) to work with the model. Parameters and return values are modeled as Data Transfer Objects (DTO) and hence no Hibernate model classes will ever leave the DAO layer.The business logic is made available in the business service class which increases maintainability and easy debugging if necessary.

* Hibernate/DB Tier:

The DAOs encapsulates the database access. For all practical purposes we are using Hibernate (v 2.1) as the OR mapping layer. This saves development time to write SQLs for executing insert and update statements find by primary key etc. For each value object that directly or compositely represent a table in the database we have Hibernate mapping files.

For some complex data retrieval however we will be using raw SQLs (independent of database) from the DAOs and populate the Value Object POJOs. In those specific cases the DAOs will be having direct access to the Databases using the available connection. The connection properties of the DB Manager holding the data sources direct the request to the appropriate database.

Issues that may rise of Hibernate:-

Hibernate no longer supports dynamic proxies

The Hibernate has issues using Microsoft’s driver especially when using SqlServer2000. It appears that the failures are due to some strange handling of dates.

Hibernate has issues with Informix Databases due to the way JDBC implementation is done in Inform ix.

Struts Datasource access from servlet

we can access the struts configured datasource from servlet context
Steps:
1.Create a datasource in struts-config.xml

2.If you want to use multiple datasources (Multiple DB) please mention the key to each datasources.
Datasource
3.we can access the datasource fron servlet using servlet context
DataSource datasource = (DataSource)getServletContext().getAttribute(“DATASOURCE_KEY”);
Connection = datasource.getConnection();

Javascript Object Oriented Programing

How to write object oriented javascript program
step 1:
create a object
var _obj=new Object();
step 2:
create a constructor to your class
/*constructor*/
_obj.classname = function(){
}
step 3:
create a prototype to your class
_obj.classnamet.prototype = {
//write functions and variables here
variablename:’value’
funcname:function(param){
this.variablename=value;
},
funcname:function(param){
}
};
//create class
var classname= _obj.classname;

//use the classname in other js to instantiate the class
var objname = new classname();
objname .funcname(param);

Sample Program
—————–
var wpress=new Object();
wpress.Wordpress = function(){
this.attributes=new Array();
};
wpress.Wordpress .prototype = {
flashObjId: ‘lzapp’,
flashDivId: ‘flashcontent’,
setAttribute:function(_key,_value){
this.attributes[_key]=_value;
},
getAttribute:function(_key){
return this.attributes[_key];
},
setIDs: function(pFlashObjId, pFlashDivId){
this.flashObjId=pFlashObjId;
this.flashDivId=pFlashDivId;
}
};
var WordPress= wpress.WordPress;

/*in other js*/
var mypress=new WordPress();
mypress.setIDs(‘myapp’,’mydiv’);

Java + Unix commands

Unix commands are executed from java runtime.For example if we want the last 100 lines from log file it is better to use exuction of unix command tail -100 /path/jboss.log

Java code:
———–
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class ServerLog{
public static void main(String args[]){
try{
Process process = Runtime.getRuntime().exec(“tail -10 D:/red5-0.9.0/log/avm.log”);
BufferedReader stdout = new BufferedReader(new InputStreamReader(process.getInputStream()));

while ((s = stdout.readLine()) != null) {
System.out.println(s);
}
}catch(Exception e){
System.err.println(“Exception reached: ” + e) ;

}
}
}

Windows XP and Dos Unix style commands

TheWindows XP does not normally come with Unix commands Ex:’tail’ tool, it is available in the Windows 2003 Resource Kit. It is a large download, but besides the ‘tail’ command, the Windows 2003 Resource Kit also provides tools to remap keys, query the Active Directory, and more. To download and install the Resource Kit:

Steps to support windows xp for unix commands
1.Go to the Microsoft Windows Server 2003 download section at
http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en
2.Download and install it
3.reboot the system
The unix commands are working from Dos