Monday, June 23, 2014

Differences between filter and Interceptors?

1. Filters are part of the Servlet API, Interceptors are Struts 2.  

2. The Interceptor stack fires on requests in a configured package while filters only apply to their mapped URLs. 


3. Interceptors can be configured to execute or not depending on specific target action methods via excludeMethods and includeMethods while Filters lack this feature. 


4. 
 struts2.x required a filter StrutsPrepareAndExecuteFilter is act as a centralized request processing.


If Javascript is disabled, Does AJAX controls work

HI, 

Yes we have an option to use AJAX when javascript is disabled. Many ppl consider that without javascript AJAX wont work... Yes its correct but for every problem always an alternative is thr... The alternative for you aproach is DEGRADABLE AJAX 

"Degradable Ajax" is Degrading gracefully with old browsers, and browsers with JavaScript disabled. 

http://particletree.com/features/the-hows-and-whys-of-degradable-ajax/ 

IF you write AJAX code to work in an environment independent of browser settings, thats termed as degradable AJAX (it works even when javascript is enabled/disabled). 

Friday, June 20, 2014

Advantages of Struts 2.0 compare with Struts 1.2

Advantages of Struts 2.0 compare to Struts 1.2


1) Struts 1.2 is class driven but the framework should be an interface driven(according to the proper design) so that we can extend some other classes
Struts 2.0 is interface driven we can write without using interface or with interface or with a class
2) In Struts 1.2 checkboxes are required to control it using reset() method
In Struts 2.0 check boxes does not require any kind of special appl for false values
3) In struts 1.2 all the action classes must extend action.
In struts 2.0 any class can be used as an action class and it can input properties by using any Java Bean directly to the action class.
4)Struts 2.0 actions are spring friendly and so easy to integrate with spring.
5)Struts 1.2 we have to use DWR if we require the Ajax feature.
In struts 2.0 we will be getting the Ajax features directly.
6)In struts 1.2 Request Processor is applicable for all the flows and it is a drawback.
In Struts 2.0 we can implement Request Processing logic for specific flows using Interceptor concept.
Struts  +   WebWork     =    Struts 2.0
7) In struts 1.2 for all the requests one action object will be created and used for all the requests.
In Struts 2.0 for each request one action object will be created because it contains the form data also.
8)In Struts 1.2 we should not declare instance variables in the action class because multiple threads will be using the same action object and instance variables.
In Struts 2.0 we can declare instance variables.
In Struts 1.2 if we want to use instance variables then use synchronized blocks
9) Struts 2.0 is a simplified design because it is interface driven and those are just like POJO’s.
10)Struts 2.0 is not http dependent, It is loosely coupled.
11)In Struts 2.0 action classes are simplify it’s like POJO’s and using inversion of control If we require we can get request and response objects.
12)No more action forms in Struts 2.0
13)Struts 2.0 testing is more easy because it’s not API dependent.
14)In Struts 2.0 all the basic default configuration we can get it automatically.
extends =”struts-default”
15)In Struts 1.2 it is difficult to switch from one presentation to another presentation layer.
In Struts 2.0 it is very simple to switch from one presentation to another.
16) In Struts 2.0 we get improved Results it’s like Action Forwards.
Struts 2.0 Results provides flexibility to create multiple types of outputs and in actual it helps to prepare the response.
17) In struts 2.0 we can get better Tag features like we can get the tags for freemarker also.
18)In struts 2.0 Annotations are introduced Applications in 2.0 can use the java 5 annotations as an alternative to xml and java properties configuration. Annotations minimize the use of XML.
19)Validations
Struts 1.2 and Struts 2.0 both supports the manual validation via a validate method.
Struts 1.2 uses validate method on the ActionForm, or validates through an extension to the commons validator.
Struts 2.0 supports manual validation via the validate method and the xwork validation framework, The xwork validation framework supports chaining validation into sub-properties using the validations defined for the properties class type and the validation context.
20) Threading Modal
In struts 1.2 action resources must be thread safe or synchronized, so actions  are singleton and thread safe.
There should only be one instance of a class to handle all requests for that action. The singleton strategy  places restrictions on what we can be done with struts 1.2. Actions and require extra care to develop.
In Struts 2.0, Actions objects are instantiated each request, so there are no thread-safety issues. In practice, servlet containers generate many throw away objects per request, and one more objet doesn’t impose a performance penalty or impact garbage collection.
21) Type Conversion
Usually Struts 1.2 ActionForm properties are all strings, Struts 1.2 uses “common-BeanUtils” for type conversion. These type convertors are per-class and not configurable per instance.
Struts 2.0 uses OGNL for type conversion, The Framework includes converters for basic and common  object types and primitives.
22) Binding Values into views in the view Section.
Struts 1.2 uses the standard jsp mechanism to bind objects (processed from the model section) into the page context to access.
Struts 2.0 uses a “ValueStack” technology so that the taglibs can access the values without coupling your view to the object type it is rendering. The ValueStack strategy allows the reuse of views across the range of types which may have the same property name b different property types.
23)Expression Language
Struts 1.2 integrates with JSTL, so it uses the JSTL-EL. The struts EL has logic object graph traversal, but relatively weak collection and indexed property support.
Struts 2.0 can also use JSTL, however it supports more powerful and flexible expression language called “Object Graph Notation Language”(OGNL)
24)Harvesting Input
Struts 1.2 uses and ActionForm object to capture input, and all ActionForms needs to extend a framework dependent base class. Java Beans cannot be used as ActionForms, so the developers have to create redundant classes to capture input.
Struts 2 uses Action Properties (as input properties independent of underlying Framework) that eliminates the need for a second input object, hence reduce redundancy.
Additionally Struts2, Action properties can be accesses from the web page via the tag libs.
Struts 2.0 also supports the Action form properties as well as POJO from objects and POJO Actions. Even rich object types, including business or domain objects, can be used as input/output objects.
Interceptors that can be preprocess and/or postprocess a request.
Action classes that can call business logic and data access code.
Results that can prepare views using JavaServerPages, Velocity and FreeMarker templates.