Comparison of presentation layer frameworks struts/tapestry/JSF
【Abstract]Struts/JSF is suitable for general data page entry systems. For selection of struts and JSF, my personal opinion is: if you are a new system, you can start with JSF directly. If you have used struts, you do not need to convert it. If you need to switch, you can consider JSF and Tapestry together.
Struts/tapestry/JSF is a framework technology that combines old and new J2EE performance layers. From the time of its birth, Struts should be relatively early and widely used. tapestry 3.0 has gradually attracted wide attention. Just as tapestry is about to show its strength, Sun has introduced the JSF standard technology, although JSF was not yet mature at the beginning, it set aside a blank period. However, as jsf1.1 standard was launched, JSF began to launch a positive attack and the noodle was unveiled.
In fact, JSF and tapestry are not the same competing technologies that match the header. The two have their own focuses, but they are relatively subtle, however, this tiny point may bring different feelings and changes when implementing a large project.
First, we can abstract the technical architecture of the presentation layer framework from a height. It can be said that all the presentation layer framework technologies must implement the function architecture:
Of course, we don't need to talk nonsense about the MVC mode. The MVC mode is the benchmark mode, and now the framework technology no longer has to fight for the MVC mode. Based on the MVC model, a presentation layer framework needs to implement three functions in the diagram:
1. The content of a component object can be displayed on the current page. Instead of writing the Java code "Call object method" on the JSP page just like JSP.
2. When the user presses the page to submit a button or link, the event occurs. In this case, the server side should be triggered and the parameters of the current page should be submitted to the server. This mechanism is manifested in Form submission and parameter Links <a href = ""> </a>
3. directly jump from a page view to another page view for simple navigation.
We use the table below to compare the technical details of these three frameworks when implementing each function, so as to draw out their similarities and differences and their key points.
|
Struts |
Tapestry3.0 |
JSF |
Component requirements displayed in view |
The component must inherit the actionform |
Explicit and implicit calls The component must inherit the basecomponent |
Common pojo No inheritance required Managed Bean |
Display granularity of Components in view |
The view page can only display the actionform corresponding to the form. In the configuration, the action actionform page can only be. |
You can embed a component into any row of the page, with no limit on the number of components used. |
Same as tapestry |
Page partition tiles |
Using tiles label library implementation requires additional tiles-def.xml configuration files |
A widget has its own view page. by calling a widget, you can directly combine multiple pages. Strong natural page combination is its characteristic. |
Subview is implemented through the component + tag library, but if layout needs to be reused, it must be combined with tiles. |
Page Jump |
Use the tag library HTML: Link to specify the target URL. The URL name must be named against the path in the configuration file, coupled with the component action. |
The URL name is the name of the target component, which does not involve URL or path operations. |
Similar to struts, you also need to find it in the configuration file and separate it from the component. |
Parameter transfer |
When using HTML: link, it is troublesome to pass more than one parameter. |
Directly call the component and assign parameters directly. There is no limit on the number of parameters. |
Pass Parameter separation to component |
Event triggering |
Submit is submitted through the form for activation. Fields in the form cannot be refined. |
An event can be attached to each field in the form. The event component must implement the pagelistener interface. |
Same as tapestry, the event component must practice the actionlistener Interface |
|
Struts Component Programming Model
Struts implements component programming with some complexity: It is often a headache to introduce multiple components to a page, because struts cannot directly introduce multiple components, and it must be around some circles:
Generally, there are two cases: if the same action can deal with these components, there are two methods in this case:
1. Load these components into one actionform, such as mapform;
2. Manually load multiple components into the scope, such as request/session, and obtain them in JSP based on their names.
Both methods have their disadvantages: the first method is often an actionform that becomes a hodgedge, in violation of the OO dispatch encapsulation principle; the second method actually returns to JSP programming;
In the second case, if these components must be processed by different actions in advance, each component must go through the action --> actionform process. In this case, there are two methods:
1. Use tiles to output different processes to different regions of the same page. Is a parallel processing method.
2. connecting multiple processes at the beginning and end, the result of the first action forward is the second action, and a JSP is output. In this JSP, multiple actionforms of the preceding processes can be used, this is a serial method.
Struts component model disadvantages
Struts component programming must be limited to the action, actionform, and JSP boxes, which are relatively difficult, while tapestry and JSF do not have many technical boxes, the two allow programmers more freedom and convenience in component programming. This is also the advantage of component framework.
Struts tag Library
In struts, the tag library is often used to display the content in the actionform component. This involves a combination problem. The tag library is written by someone else. Refer to the struts tag library usage, components are their own, and the difficulty and trouble are reflected in this combination point.
The basic idea of JSF is similar to that of Struts. However, if you change the tag library, you also need to consider the combination of the tag library and component. However, because the component is a common component, there is no restriction, this is easier than struts.
Tapestry uses the component library concept to replace the label library, and does not have the label library concept. In this way, there is no need to combine the label library with its own components. They are all used by components, standard Components and custom components of the tapestry in the component, which is also a way of thinking for people who are in contact with the JSP system to learn about tapestry.
Take page Jump as an example. Page jump is achieved by link <a href = "target"> </a>. links are frequently used elements of pages.
The HTML: link provided by struts is especially inconvenient when it is frequently used, especially when multiple parameters are passed: the page value of HTML: link is the path to jump to the target page or action, this path usually needs to find the corresponding path of the action in the struts-config.xml, once the PATH value of the configuration file is modified, it involves all related pages to be modified.
JSF divides the concept of link into two aspects: navigation nature and event activation. In terms of navigation, you still need to configure faces-config to query the value of navigation from-outcome.
Because tapestry does not have the label library concept and only has the components or pages, the link jump target is either a component or a page, which is concise and simple and has no redundant path concept, the component name, that is, the object name. The component name and path name are combined into one.
Summary
JSF is similar to struts to a large extent, rather than like tapestry. It can be said that it is a type of struts 2.0, all in the form of tag library + component, however, the concept of JSF components does not have to inherit the actionform restrictions as struts does; JSF must be fine-grained in terms of event granularity. Unlike struts, a form is an event, JSF can be refined to every field in the form.
JSF is similar to tapestry only in terms of component and event mechanisms, but is not like Tapestry as a complete component framework. Therefore, if you want to build a system with high page flexibility, choosing tapestry is the first consideration.
Struts/JSF is suitable for general data page entry systems. For selection of struts and JSF, my personal opinion is: if you are a new system, you can start with JSF directly. If you have used struts, you do not need to convert it. If you need to switch, you can consider JSF and Tapestry together.
In addition, JSF/tapestry not only supports HTML, but also supports multiple client languages such as WML or xui.
Relationship between the three: If struts is left, then tapestry is right, while JSF is middle, and moderate is the consistent policy of sun.
Of course, you can also express your usage of any of the three in practice to make a comparison between them.