Wednesday, May 23, 2012

Starting of J2ME application


# J2ME
—Java 2 Platform, Micro Edition, is the Java platform meant to run on small devices. Currently, these devices are typically cell phones or PDAs, but J2ME is also used on other embedded systems. A configuration, a profile, and optional packages are what compose a J2ME platform.

# CLDC
—Connected Limited Device Configuration is a J2ME configuration that is currently most often used on mobile phones. It contains a run time environment and a core API that are appropriate for the limited processor speed and memory size of mobile devices.

# MIDP
—Mobile Information Device Profile is the set of APIs that provides higher-level functionality required by mobile applications, such as displayable components (“screens”) and network communication.

#MIDlet
—A class required by all MIDP applications. It acts as the interface between the application and the device on which it is running. A MIDlet is similar to a main class in a J2SE project.

# Preverification
—When building an application that runs with CLDC, all compiled classes must be preverified. Preverification is a process that adds annotations used by the CLDC JVM to a class file’s bytecode. The preverification process also ensures that the class contains only code that will run on its CLDC version.

# Device fragmentation
—Term used for the variations between mobile platforms that prevent a single application from automatically running optimally on all phones. These differences can be physical (screen size, screen color depth, available memory, and so on) or software related (available APIs, CLDC/MIDP version, and so on).

# Preprocessor
—Though preprocessor is not a J2ME-specific term, NetBeans Mobility Pack ships with a preprocessor that is used as part of its device fragmentation solution. The preprocessor is an Ant task that runs before files are compiled. It looks for special Java comment tags within the file and adds or removes line comments based on these tags.

# Obfuscation
process that makes class files difficult to reverse engineer. This is usually accomplished by, at least, replacing names of packages, classes, methods, and fields with short identifiers. This has the result of decreasing the size of your application and, therefore, is an important aspect of the mobile application build process.

more

Thursday, March 29, 2012

different scopes of managed bean in JSF

Managed beans can have different scopes. They are as:

1. Request
2. Session
3. Application
4. None

A scope of request means that the bean is only available in a single HTTP request. Managed beans can also have session scope, in which case they are available in a single user's HTTP session. A scope of application means that the bean is accessible to all users in the application, across user sessions. Managed beans can also have a scope of none, which means that the managed bean is not stored at any scope, but is created on demand as needed. Additionally, managed beans can have a scope of view, in which case the bean is available until the user navigates to another page. View scoped managed beans are available across Ajax requests.

Wednesday, March 28, 2012

PROJECT_STAGE in configuration file of JSF project

when we start a JSF project using netbeans, we get a skleton project containing two files at first.

a single facelet file called index.xhtml,
a web.xml configuration file


web.xml is the standard, optional(from version 3.0) configuration file needed for Java web.

If we observer we find that the NetBeans automatically sets the JSF project stage to Development, setting the project stage to development configures JSF to provide additional debugging help not present in other stages.

The following are the valid values for the javax.faces.PROJECT_STAGE context parameter for the faces servlet:

1.Development
2. Production
3.SystemTest
4.UnitTest

Development project stage adds additional debugging information to ease development. The Production project stage focuses on performance. The other two valid values for the project stage (SystemTest and UnitTest), allow us to implement our own custom behavior for these two phases.

The javax.faces.application.Application class has a getProjectStage() method that allows us to obtain the current project stage. Based on the value of this method, we can implement the code that will only be executed in the appropriate stage.

Wednesday, March 21, 2012

Line limit for Text Area

In a HTML page, text area is used to accept multiple line texts at once. But some times, we may need to fixed the no. of line in a text area of web page. There is not attribute available for this purpose. This will have to implemented using javascript. The required function to check the no. of line as well as the no. of characters in a text area may be as:

<script type="text/javascript">

var alert_title='Input Restriction';

function limitTextarea(textarea,maxLines,maxChar){
var lines=textarea.value.replace(/\r/g,'').split('\n'),
lines_removed,
char_removed,
i;
if(maxLines&&lines.length>maxLines){
//alert('You can not enter\nmore than '+maxLines+' lines');
lines=lines.slice(0,maxLines);
lines_removed=1
}
if(maxChar){
i=lines.length;
while(i-->0)if(lines[i].length>maxChar){
lines[i]=lines[i].slice(0,maxChar);
char_removed=1
}
//if(char_removed)alert('You can not enter more\nthan '+maxChar+' characters per line')
}
if(char_removed||lines_removed)textarea.value=lines.join('\n')
}

function watchTextarea(){
document.getElementById('resticted').onkeyup()
}

function set_ie_alert(){
window.alert=function(msg_str){
vb_alert(msg_str)
}
}
</script>

and the above function can be called as

</script>
</head>
<body>
<textarea onkeyup="limitTextarea(this,6,40)" style="width:400px;height:200px" wrap="off" id="resticted" onfocus="focus_watch=setInterval('watchTextarea()',250)" onblur="clearInterval(focus_watch)">some text</textarea>
</body>
</html>

why JSF?

Java Server Faces technology , developed by Java Community Process(JCP) ,simplifies the development of Java Based web applications.
Java Server Faces is a component oriented and event driven framework for web applications. JSF eases the development of GUI for web applications. JSF allows the programmers to work with extensible user interfaces like buttons, text boxes, check boxes etc... Programmer writes the code for particular event such as button clicked. This makes programming much easier and now the there is no need to write request and response processing logic.

Main feature of JSF is ease of use. Developing web applications is easier and faster than other frameworks like struts because JSF supports UI components and easy event handling.JSF is based on well established Model-View-Controller (MVC) design pattern. Applications developed using JSF frameworks are well designed and easy to maintain then any other applications developed in JSP and Servlets.

JSF includes mainly:
Set of APIs to represent and manage state of components that helps server side validation, event handling, page navigation, data conversion etc.
JSP custom tag library to create UI components in a view page.

The UI (user interface) created using JSF technology runs on server and output is shown to the client. Goal of JSF is to create web applications faster and easier. Developers can focus on UI components, events handling, backing beans and their interactions rather than request, response and markup. JSF hides complexities to enable developers to focus on their own specific work.