Difference between JSF and Struts

Source: Internet
Author: User

JSFAndStrutsTaglib is used to process the presentation layer. In jsp pages, both use a set of tag libraries to process the interaction between the page expression and the model layer.

It is said that the main leader of JSF is the author of struts, so there are many similarities between the two.

Both use taglib to process the presentation layer: in jsp pages, both use a set of tag libraries to process the interaction between the page expression and the model layer.

Both use bean as the model layer corresponding to the jsp page. The model layer saves the data on the jsp page and can perform some verification work. In struts, It is FormBean and in JSF, It is back bean.

Bean is used as the control layer, and ActionBean is used in Struts to process business logic. For simple applications, business logic code can be directly written in ActionBean, you can also call another bean or EJB to process the business logic. For JSF, backing bean is used to process the business logic. Similarly, backing bean can also directly write the business logic or call other beans to process the business logic.

Xml configuration files are used to handle bean configuration, page navigation, and other issues, increasing system flexibility.

All use resource files to handle internationalization and localization issues.

However, there are many differences between the two, which are described below:

1. First, the two have different focuses,StrutsIt focuses on the control layer and how to dispatch and process user requests. Therefore, the taglib function of the presentation layer is not powerful enough. While JSF focuses on the presentation layer and implements a large number of standard components, allowing developers to have more control over the presentation layer. Meanwhile, JSF implements an open architecture, allows developers to create their own components or inherit from existing components to develop more powerful components. I think this is the biggest feature of JSF. (Similar to vcl and. Net Component)

2. The model layer corresponding to jsp uses FormBean in Struts to save user input data. Generally, the field type is String. in addition, you can perform simple verification. Of course, dynamic FormBean cannot be used for verification in FormBean. In Struts, jsp and FormBean are closely combined. As long as a jsp is written, it must correspond to a FormBean. At the same time, each component in jsp corresponds to the field with the same name in FormBean. I think this is not flexible. For example, you must consider the implementation of FormBean in the background when developing a page. However, if the page does not have FormBean, the program will run incorrectly. InJSFIn, components on the JSP page are associated with the backing bean field through the value property, which provides greater flexibility. Each component on the page can correspond to the same backing bean, it can also correspond to different backing beans (of course, I think that in general applications, components on a page still correspond to a backing bean better ), in addition, you can design the backing bean after designing the page without considering how to design the backing bean.

3. For data verification, Struts can perform verification in the FormBean verification function, or use validator for verification. (For this verification method, I have not tested it and I do not know how it works, hope you have any experience !). In JSF, some quasi-validator can be used to perform some simple verification on the input data, such as verifying the value data range and whether the field is required. However, the verification feedback is in English. If the information cannot be customized, it is not suitable for domestic applications. Currently, I have not found a way to customize the feedback. In addition, components of the input type can be associated with a verification method of the backing bean through the validator attribute. It is also a way to verify the event processing method.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.