Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of SimpleFramework component development

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "what is the method of SimpleFramework component development". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Simple components are based on Web, and any UI or business logic related to Web can become Simple components.

A single background logic is not supported by Simple components, such as establishing a network connection, accessing data, etc., but these business logic associated with the front-end Web, such as Web-based network traffic monitoring, can become Simple components.

Simple component hides the complexity of front-end Web (HTML, Javascript, CSS, etc.). At the same time, it provides consistent and operational business logic interfaces for back-end logic, and developers are free to design these interfaces.

Simple components are open and friendly, and any developer can easily develop their own components according to the specification.

Four interfaces that need to be implemented

For custom components, you must implement the following four interfaces (classes):

Interface IComponentRegistry

Define a registered class instance of the component and register it in the system registry when the system is initialized so that the custom component can be used. The code is as follows:

ComponentRegistryFactory.getInstance () .regist (new YourComponentRegistry (servletContext))

Definition and description of the main functions of IComponentRegistry:

String getComponentName (); the name of the component, which is the component label declared in the XML description and must be * IComponentRender getComponentRender (); get the renderer instance of the component, see IComponentResourceProvider getComponentResourceProvider () for more information; get the resource provider instance of the component, see AbstractComponentBean createComponentBean (PageParameter pageParameter, Element component) for more details; and create the meta-information definition instance of the component. The meta-information of the component comes from the XML description file, and the instance initializes the properties of the Bean as defined in XML

Interface IComponentResourceProvider

The resource provider of the component, which mainly defines the resource environment on which the component must run, including Javascript, CSS, jar, or other registered components.

Definition and description of the main functions of IComponentResourceProvider:

ZipInputStream getRequiredResource (); gets all the resources required by the component in the form of Zip. A typical directory structure may be as follows: ZIP |-- jsp |-- css |-- images |-- flash |-- jar String getResourceHomePath (); get the Web access path after the component resource is deployed. For example, if you want to get the image path in the component resource, you can access it through the following code: request.getContextPath () + getResourceHomePath () + "/ images/t.png" String [] getCssPath (PageRequestResponse requestResponse); String [] getJavascriptPath (PageRequestResponse requestResponse); String [] getJarPath (); declare the specific resources that the component depends on, which will be appropriately added by the system to the browser's HTML String [] getPageJavascriptPath (PageRequestResponse requestResponse). String [] getPageCssPath (PageRequestResponse requestResponse); as above, declare the specific resource on which the component depends, except that the path is based on the requested resource and can reference the Javascript and css resources String [] getDependentComponents () of other components; get other registered components on which the component resource depends. For example, a business selection window depends on basic window components

Interface IComponentRender

Component renderer, which is responsible for generating HTML (rendered via IComponentHtmlRender) or Javascript code (rendered via IComponentJavascriptRender) to the browser.

Another important role of the component renderer is to invoke the business logic defined in Handle.

Definition and description of the main functions of IComponentHtmlRender:

String getHtml (ComponentParameter compParameter); get the HTML String getHtmlJavascriptCode (ComponentParameter compParameter) that the component is rendered; get additional related Javascript code

Definition and description of the main functions of IComponentJavascriptRender:

String getJavascriptCode (ComponentParameter compParameter); gets the Javascript code that the component is rendered

AbstractComponentBean-like

The description (meta) information class of the component. The description information of the component is set by the component developer according to the specific requirements of the component. The description information of the component comes from the XML description file. The developer must initialize the properties of the component Bean according to the definition in XML and refer to the definition in the interface IComponentRegistry.

Define XML Schema

The main purpose of XML Schema is to verify the correctness of the XML description file. With the help of IDE tools such as Eclipse, the definition properties of components can be written more accurately and quickly.

Component developers need to add XML Schema support to the component and include it in the simple .xsd file.

Define Handle

Handle is the core processing class of the component business, and it is a general way for the interface left to the user to contact the behavior of the component. The design of Handle is done by component developers, so that business logic that is more suitable and easier to operate can be designed according to the behavior of components. Many Web frameworks only provide controllers such as Action, which is too much for business developers to do, and Handle makes it clear what to care about and how to do it.

To give a concrete example, "data paging" is an effective way to dynamically handle a large number of data sets, here is the definition of IPagerHandle:

Int getCount (ComponentParameter compParameter); void process (ComponentParameter compParameter, int start)

IPagerHandle defines only two business function interfaces: getCount gets the total number of result sets, and process processes cursors whose current position is the result set of start. Combined with the definition of PagerBean (the number of displays per page, etc.), it is easy to calculate the dataset of the currently displayed page.

Handle must inherit from the interface IComponentHandle,IComponentHandle defines some default component business behavior.

This is the end of the content of "what is the method of SimpleFramework component development". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report