Dispatch Annotations
@UrlBinding
This annotation can be applied to ActionBean classes to override the generated URL binding for the class with a specific URL. It binds the ActionBean to the specified path so that this bean is invoked in response to that path being requested.
Example:
@UrlBinding("/ValidateLogin.action")
public class ValidateLoginActionBean implements ActionBean {
.
.
}
@HandlesEvent
When applied to an ActionBean method, this annotion denotes that the method should be executed when there is no event name provided in the request. Note: when only one handler method exists, it is deemedto be the default without need for annotation.
@DefaultHandler
When applied to an ActionBean method, this annotion denotes that the method should be executed when there is no event name provided in the request. Note: when only one handler method exists, it is deemed to be the default without need for annotation.
@SessionScope
Causes the ActionBean, the first time it is used within a user's session, to be placed in the user's HttpSession. On subsequent requests the ActionBean will be retrieved from the HttpSession and re-used.
Validation Annotations
@DontValidate
When applied to an event method, this annotation overrides the stripes validation process, skipping the typical required field and field value checks. ActionBean properties are still converted and bound where possible with the use of this annotation.
@Validate
This annotation defines the rules of validation for a single field in an ActionBean.
Example:
@Validate(required = true)
private String username;
@ValidateNestedProperties
This annotation can be used for complex object validation. For example, if your ActionBean has a User member variable, with a username property and a password property, you can apply individual field validation to each of the sub fields of the object. This validation may only include @Validate definitions.
Example:
@ValidateNestedProperties(
Unknown macro: { @Validate(field="username",
required="true"), @Validate(field="password",
required="true")}
)
Data Binding
Stripes performs data binding directly from submitted form fields or query string parameters to the backing ActionBean as described in the overview above. In addition to binding simple types, Stripes also supports binding complex classes.
Example:
public class User {
private String firstname;
private String lastname;
private boolean admin=false;
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public boolean isAdmin() {
return admin;
}
public void setAdmin(boolean admin) {
this.admin = admin;
}
}
//Action Bean class
public class MessageActionBean implements ActionBean {
private User user;
public void setUser(User user) {
this.user = user;
}
public User getUser() {
return user;
}
public Resolution saveUser() {
userManager.saveUser(getUser());
}
…etc…
How To Begin With Servlets
This blog is intended for beginers with Servlets.
Monday, June 14, 2010
Stripes - Action Bean/Request Life Cycle
Stage0: Pre-processing by the Stripes filter
Firstly it "hides" the current Configuration somewhere, so that anywhere in the application the Configuration can be retrieved by calling StripesFilter.getConfiguration()
Secondly it resolves the Locale that should be used for the current request. It does this by invoking the configured LocalePicker.
Thirdly it wraps the HttpServletRequest with a StripesRequestWrapper. The wrapper ensures that HttpServletRequest.getLocale() always returns the picked Locale.
At this point the flow of control could flow directly to a JSP. If the request is for an ActionBean event, then we continue on to the Stripes DispatcherServlet.
Stage1: Resloving the Action Bean
Firstly the DispatcherServlet fetches the configured ActionBeanContextFactory and uses it to manufacture an ActionBeanContext. The DefaultActionBeanContextFactory looks for a configured class name, and if none is found, creates a new ActionBeanContext.
The DispatcherServlet then fetches the configured ActionResolver and uses it to resolve the appropriate ActionBean instance. The default ActionResolver is the NameBasedActionResolver.
Stage2: Handler Resolution
DispatcherServlet uses the ActionResolver to determine the name of the event submitted. If there was no identifiable event name then the ActionResolver is asked for the @DefaultHandler method, otherwise it is asked for the method which handles the named event.
The event name is then set on the ActionBeanContext.
Stage3: Binding & Field validation
The process of binding and validation, while driven by Stripes, allows the ActionBean author to assert a certain amount of control.
• @Validate and @ValidateNestedProperties allow ActionBeans to specify validations to be run onproperties
• @DontValidate allows individual handler methods to request that validation be by-passed
• ValidationMethod allows ActionBeans to plug in custom validation logic
• ValidationErrorHandler allows ActionBeans to intercept validation errors and decide what happens next
Stage4: Custom Validation
Validation methods may be specified to run only when no errors have been generated so far, or always.An application level default exists and can be configured; if not configured the default is not to run validation methods when errors exist.
When errors are discovered during validation and the ActionBean implements ValidationErrorHandler the handleValidationErrors(errors) method will be invoked. In this method bean authors may manipulate the collection of errors (perhaps emptying it, which has significant implications) and/or return an alternative Resolution. If a Resolution is returned it is executed immediatley.
Stage5: Executing the Action Bean
If there is no validation errors, the DispatcherServlet will invoke the Handler method on the Action Bean.
Handler method should return a resolution,If ActionBean returns a non-null resolution the DispatcherServlet will call its execute() method to complete the request.
Firstly it "hides" the current Configuration somewhere, so that anywhere in the application the Configuration can be retrieved by calling StripesFilter.getConfiguration()
Secondly it resolves the Locale that should be used for the current request. It does this by invoking the configured LocalePicker.
Thirdly it wraps the HttpServletRequest with a StripesRequestWrapper. The wrapper ensures that HttpServletRequest.getLocale() always returns the picked Locale.
At this point the flow of control could flow directly to a JSP. If the request is for an ActionBean event, then we continue on to the Stripes DispatcherServlet.
Stage1: Resloving the Action Bean
Firstly the DispatcherServlet fetches the configured ActionBeanContextFactory and uses it to manufacture an ActionBeanContext. The DefaultActionBeanContextFactory looks for a configured class name, and if none is found, creates a new ActionBeanContext.
The DispatcherServlet then fetches the configured ActionResolver and uses it to resolve the appropriate ActionBean instance. The default ActionResolver is the NameBasedActionResolver.
Stage2: Handler Resolution
DispatcherServlet uses the ActionResolver to determine the name of the event submitted. If there was no identifiable event name then the ActionResolver is asked for the @DefaultHandler method, otherwise it is asked for the method which handles the named event.
The event name is then set on the ActionBeanContext.
Stage3: Binding & Field validation
The process of binding and validation, while driven by Stripes, allows the ActionBean author to assert a certain amount of control.
• @Validate and @ValidateNestedProperties allow ActionBeans to specify validations to be run onproperties
• @DontValidate allows individual handler methods to request that validation be by-passed
• ValidationMethod allows ActionBeans to plug in custom validation logic
• ValidationErrorHandler allows ActionBeans to intercept validation errors and decide what happens next
Stage4: Custom Validation
Validation methods may be specified to run only when no errors have been generated so far, or always.An application level default exists and can be configured; if not configured the default is not to run validation methods when errors exist.
When errors are discovered during validation and the ActionBean implements ValidationErrorHandler the handleValidationErrors(errors) method will be invoked. In this method bean authors may manipulate the collection of errors (perhaps emptying it, which has significant implications) and/or return an alternative Resolution. If a Resolution is returned it is executed immediatley.
Stage5: Executing the Action Bean
If there is no validation errors, the DispatcherServlet will invoke the Handler method on the Action Bean.
Handler method should return a resolution,If ActionBean returns a non-null resolution the DispatcherServlet will call its execute() method to complete the request.
Java Frameworks Comparison
Stripes
Stripes is a presentation framework for building web applications using the latest Java technologies. The main driver behind Stripes is that web application development in Java is just too much work! It seems like every existing framework requires gobs of configuration .
Best Feature: No Configurations. Annotation based programming makes coding more interesting and easy.
Struts2
Apache Struts 2 is an elegant, extensible framework for creating enterprise-ready Java web applications. The framework is designed to streamline the full development cycle, from building, to deploying, to maintaining applications over time.
Best Feature : No more ActionForms! Use any JavaBean to capture form input or put properties directly on an Action class. Use both binary and String properties! and its enhanced and rich tags
Spring MVC
Spring Web MVC is the own web framework of Spring Framework.The Spring MVC Framework’s architecture and design are in such a way that every piece of logic and functionality is highly configurable. Also Spring can integrate effortlessly with other popular Web Frameworks like Struts, WebWork, Java Server Faces and Tapestry. It means that you can even instruct Spring to use any one of the Web Frameworks.
Best Feature : Speed development. Now so many Annotations are also included (v2.5). Its from SpringSource and have a good support too.
Wednesday, May 12, 2010
Introduction

Have you Interested in server side coding, but not doing that only beacause of you are a core java developer. No need to be like that any more,the j2ee concepets are no more tougher.Those who have sufficient core java knowledge can be a j2ee developer.
How To Begin
It is assumed that you have necessary knowledge in core java.Now a days tha java web applications are purely based on java servlets.Servlets were invented by Sun micro system to manage web applications in a well manner.If you are already aware of j2ee conceptes, then deffenetly you will come across terms like servelts,jsp,javascript,xml,html etc.Before starting try to obtain basic knowledge in these.
What is a Web Framework?
A web application framework is a software framework that is designed to support the development of dynamic websites, Web applications and Web services. The framework aims to alleviate the overhead associated with common activities used in Web development.
A Framework making the coding easier and simple since the majority of the basic functionalities will be available in in-built classes.
Subscribe to:
Posts (Atom)