OFBiz attack on the second section. Control understanding and Creation

Source: Internet
Author: User

The first thing to say is that learning ofbiz, to go to http://ofbiz.apache.org/official website, to see the right menu Management Apps, and then find similar pages, to see the source method of the call.

Contoller inside defines the URL of the action jump, similar to the structs function.

<request-map uri= "Editquotetermitem" >
<security auth= "true" https= "true"/>
<response name= "Success" type= "View" value= "Editquotetermitem" save-last-view= "true"/>
</request-map>

If this is the structure, it represents a direct jump, if you want to add the execution of Judgment method.

<request-map uri= "Updatesplit" >
<security https= "true" auth= "true"/>
<event type= "service" invoke= "Assignitemshipgroup"/> or <event type= "java" path= "Org.ofbiz.product.product". Productsearchsession "invoke=" Clearsearchoptionshistorylist "/>
<response name= "Success" type= "View" value= "Splitship"/>
<response name= "Error" type= "View" value= "Splitship"/>
</request-map>

In the Event tab, if Type is service, the method that invokes the service is executed. (The service name must be unique globally, so call the service method and write the service method name directly.) The file is defined under the Servicedef folder, the naming convention is Service_xxxx.xml, the service s is lowercase), service services are defined in two types of service, one is the engine is simple way, This approach is typically used in single-table operations, which can be defined as create or delete in invoke to enable manipulation of individual objects. In most cases, however, the engine type is simple, which requires that you call the file that defines the simple method, which is usually defined under script, which is generally written for us in OFBiz. So, just need to find a similar page, and then call the relevant service is OK)

If type Java,path represents the path of the class, invoke is the method defined in the Java class.

In the Java class, the most important objects

1 delegator delegator = (delegator) request.getattribute ("delegator"); Delegator This object is the object used to invoke FindOne findlist and other methods to execute the query function. (Incidentally, ofbiz inside this way, personal feeling like ibatis, such as ORM ( Object Relational Mapping ) of the persistence layer framework.

2 map<string,object> params = Utilhttp.getparametermap (request); Get page parameters

3 Genericvalue orderheaderentity = null; Defining Model objects

4 Localdispatcher Dispatcher = (localdispatcher) request.getattribute ("Dispatcher");   Retrunmap = Dispatcher.runsync ("Createreturnheader", Persistmap); Used to invoke service service

5

Modelservice modelservice = null;
try {
Modelservice = Dispatcher.getdispatchcontext (). Getmodelservice ("Createreturnheader");
} catch (Genericserviceexception e) {
String errmsg = "Error getting model service for ServiceName, ' Createreturnheader '." + e.tostring ();
Debug.logerror (errmsg, module);
Request.setattribute ("_error_message_", "<li>" + errmsg + "</li>");
return "error";
}
map<string, object> persistmap = Modelservice.makevalid (orderheaderentity, Modelservice.in_param);

By using the Modelservice service, and then following the procedure call, the corresponding entity object is automatically passed into the parameter according to the service services being invoked, and all the parameters that are required in the service to be present in the object are obtained.

6

Eventfactory.runrequestevent (Request, Response, "Makequickreturn"); In this way, the URL link defined in control can be called directly in the Java class.

OFBiz attack on the second section. Control understanding and Creation

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.