Discussion on JSF and Struts 2

xiaoxiao2021-03-06  62

Control Layer: Struts Submit requests through the Action of FORM, distribute requests through the ActionServlet, and finally processes the request by ActionBean, implement business logic in Action, or call other business logic beans to complete the user's request and return to the client. Here, an Action is only one action, that is, a page can only be submitted to an action bean. There are some modifications that need to be submitted for multiple buttons on the page. Compared with traditional web development mode. For JSF, the event mode is used to handle the request for the user. The JSF implements an event listener to monitor events, for example, when a user clicks a button, a button clicks, and the ValueChange event listener to monitor events such as numerical changes. For example, in the page, the corresponding operation is performed by associating the action attribute of the COMMANDBUTTON button. Each different button can be associated with different methods, of course, can also be associated with the same method (this is very similar to the action bean). This development mode is relatively close to the traditional C / S mode or ASP.NET development model. This approach may be more natural for developers who turn over from the C / S architecture or ASP.NET architecture. In some simple sample programs of JSF, the ACTION submitted by the MODEL layer and JSP corresponding to JSP is usually placed in the same backing bean, ie the data processed by business logic and business logic is in the same bean. I believe that such structures can only be used in simple applications, and it is not suitable for enterprise-class development. The data associated with the page should be separated from the action, such a structure, better, compared to the structure of Struts. The method in the JSF's backing bean accesses the intuitiveness in Struts, and Request, etc. The author found a lot of examples to know how to access the data in the session. Page Navigation: About page navigation, Struts and JSF are more similar. They are all configured in XML configuration files. Each page to be jumped has an alias and jumps through an alias in the program. In addition, the jump in the Struts occurs in the ActionBean, and the Execute method finally returns an actionforward to jump. JSF finally returns a string in the event processing method, and the system matches automatic jump in the XML file. In JSF, you can also directly jump directly through the jump alias in the Action property of the JSP page, without having to process the event processing method. The management of resource files: Struts and JSF are similar to the management of resource files, and the resource files are configured in Struts-Config.xml to implement unified management of the entire program. For JSF, the resource file can be defined in each JSP page, and then the content in the resource file is accessed by the alias of the resource file. The format of the two is also different. In Struts, the format is: grade1.grade2.grade3 = Your Information, by "." To represent the level. In the JSF, the level must be expressed by the next line, such as grade1_grade2_grade3 = YOUR Information. I think it is still more intuitive in Struts. In addition, the display format of the information can be defined in the resource file of Struts, such as error.Header, Error.footer. How to define it is not clear in JSF, or can be defined by defining the properties of the Messages tag.

转载请注明原文地址:https://www.9cbs.com/read-119848.html

New Post(0)