(Reposted) Struts Best Practices 3

xiaoxiao2021-03-06  50

Page 3 of 4

Prepopulation Problem One requirement difficult to achieve is data prepopulation in a drop-down list (HTML Select tag) or in other fields. Some of these values ​​come from a database, some from the application's context, and the rest are passed from calling screens. ..................

Struts Best Practice The Form Bean's Prepopulation Can Be Accomplished Using One of the Following Approaches:

The on-demand lazy-loading technique for all such data in the application's context, which is required for prepopulation. An application screen's (JSP page) invocation mechanism can always be routed though a specific method of corresponding Action classes. Prepopulation-related code can BE PLAECED INE Method. Have DiffERENT ACTION CLASSES-ONE for Requesting and another for Submitting The JSP Pages. The Entire Module OR Application Can Share The Action Class Used for Requesting.

The Second Approach Works Well for Small Applications, Managing Numerous Action Classes Grows Cumbersome. Therefore, The First Approach Should Be Adopted.

Stack maintenance (for bread crumbs) Problem What if you need to go to a JSP page from two or more different JSP pages and subsequently return to the calling JSP page? Similarly, often developers need to go to various JSP pages in a criss-cross Manner, Which Grows More Complex When Breadcrumbs Need To Be Shown. Thus, The Application Must Remember The Pages Visited.

Struts Best Practice The Remedy Is To Maintain The Paths of All The Forwarded JSP Pages In A Stack (java.util.stack). The Following Steps Are Required for Maintaining Such A Stack:

Extend the RequestProcessor class and override the method processActionPerform (). In the overridden method, after the call to super.processActionPerform (), ActionForward's path should be stored in the Stack. In the application's parent Action class, provide methods to traverse forward and backward In The Stack.another Option IS To Utilize An Already Available Open Source Project At SourceForge.net Like Open TRANQUERA (See Resources for more details).

Context-related issues Problem If ActionForward's path and the path to which the control is forwarded differ, a context problem has resulted. More such context-related problems are quite frequent in Struts-based applications, most of which can be solved using some of Struts 'Less ExploITED Features.

Struts Best Practice Mention The JSP page's name as a path for actionforward and let the prefix-i.e.

struts-config.xml (s) has a controller tag;.. add a property in this tag named forwardPattern This property's value can be prefixed to all the ActionForward paths This property's default value is $ M $ P, which means the module prefix will Be Prefixed to Actionforward's Path. We can change this value to anything; eg, web-inf / pages / $ m $ p. as a result, all the actionforward paths will be search in the Directory Web-INF / PAGES /

/

.

For Above Solution To Work, Make Sure That ActionForward's ContexTreLative Property is Marked False. If this property is marked true, the actionforward paths.

Also Note That for ForwardPattern To Work, The Path of All ActionForwards Must Start with A /.

Form-bean scope Problem A well-managed session context can greatly boost application performance It is therefore important to understand the implications of marking the form-bean scope to request, session, or application However, the following confusions usually arise:.. If the scope of the form beans is marked request, how will the information available in one JSP page / screen also be available to another one? If the scope is session, how will the server know that the client is no longer interested in that form bean and Consequently Destroy IT?

Struts best practice State can be maintained in HttpSession (Web tier), in stateful session beans (EJB tier), or in a database. The appropriate choice should be based on what kind availability needs persist or whether the application is supposed to provide multichannel access The THE REQULE OF THUMB IS TO Main That Requires It Most. Therepore, The Best Practice; IE, Mark The Form-Bean Scope To Session.

The important question is when and how to destroy the form beans stored in the HttpSession. The session beans should be destroyed in an extended RequestProcessor based on the least-recently-accessed, to-be-removed logic. Another approach is to destroy all the Form Beans As Soon as The User Invokes a New Business Operation, Possibly from the Application Menu.

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

New Post(0)