A kind of resource multipage distribution method based on AJAX
Technical field
The present invention relates to utilize AJAX (Asynchronous JavaScript and XML) framework to carry out WEB development field, particularly a kind of resource multipage distribution method based on AJAX.
Background technology
In application system, resource and role's binding is a general problem.In existing application system, be generally by inquiry, to obtain role's list of the condition of conforming to, choose/cancel check box corresponding to certain role, realize binding/cancellation bindings of corresponding role and resource; Or choose/cancel the role of current page, to realize binding/cancellation bindings of current page role and resource.
If the role who inquires is much in the situation such as thousands of page, one by one or page by page, by itself and resource binding, just seem extremely loaded down with trivial details.
Therefore, being badly in need of a kind of method can all realize binding or cancel binding with resource the multipage role who inquires is disposable.
AJAX is the comprehensive of multiple technologies, comprises Javascript, XHTML and CSS, DOM, XML and XSTL, XMLHttpRequest.It uses XHTML and CSS standardization to present, and use DOM realizes and dynamically shows and alternately, use XML and XSTL to carry out exchanges data and processing, uses XMLHttpRequest object to carry out asynchronous data and reads, and uses Javascript binding and processes all data.
Different from traditional Web application, AJAX adopts asynchronous interactive process.AJAX introduces an intermediary between user and server, thereby has eliminated the processing-wait-processing-wait shortcoming in network interaction process.User's browser has loaded AJAX engine when executing the task.AJAX engine JavaScript language compilation, ensconces in a hiding framework conventionally.It is responsible for compiling user interface and and server between mutual.AJAX engine allows asynchronous the carrying out of reciprocal process between user and application software, is independent of exchanging between user and the webserver.Now, can call the user action that AJAX engine replaces producing a HTTP with Javascript, these demands that do not need to be again written into full page of the data edition in internal memory, page navigation, data check can be given AJAX and be carried out.
Use AJAX, can for ISP, developer, terminal user bring visible convenient:
● alleviate the burden of server.The principle of AJAX is " fetching data as required ", can farthest reduce redundant request, and responds the burden that server is caused.
● updating web, reduces user psychology and actual stand-by period.Especially, when will read a large amount of data, the situation that need not occur white screen as Reload, AJAX is used XMLHTTP object to send request and obtain server response, the Javascript operation DOM final updated page in the situation that not again being written into full page.So in the process of reading out data, what user faced is not white screen, be original content of pages (prompting frame that also can add a Loading allows user know in reading out data process), only have the content of just upgrading appropriate section after data receiver is complete.This renewal is moment, and user is almost imperceptible.
● bring better user to experience.The work of some server burdens in the past can be married again to client, utilize client idle capacity to process, alleviate the burden of server and bandwidth, conserve space and broadband lease cost.
● can call external data.Based on technology standardized and that extensively supported, do not need download plug-in or small routine.Further promote the page to present separated with data.
In sum, how AJAX technology is applied to during resource multipage distributes, all to realize binding with resource or cancellation is bound by the multipage role who inquires is disposable, is the direction place of those skilled in the art institute wish research.
Summary of the invention
Fundamental purpose of the present invention is to provide a kind of resource multipage distribution method based on AJAX, and it has been realized and has all realized binding or cancel binding with resource the multipage role who inquires is disposable.
In order to achieve the above object, the invention provides a kind of resource multipage distribution method based on AJAX, it comprises following
Step:
Step S1: bindingSet is carried out to initialization setting, its initial sets is made as to role's major key of having bound with resource in database;
Step S2: binding/cancellation bindings that user carries out at front page layout is reacted to the variation of bindingSet;
Step S3: user carries out submit operation, will newly gather bindingSet and be updated to database or other storage entity.
Preferably, in embodiment, in step S1, by described initial sets, determine whether check box is chosen to show the role who checks out, and inquires qualified role's list, the corresponding check box of each role, arranges the initial value of check box.
, in embodiment, in step S1, be preferably to retrieve at bindingSet by major key, if can retrieve, this check box is " choosing " state; Otherwise this check box is " not choosing " state.
Preferably, in embodiment, in step S2, described binding/cancellation binding comprises single role bindings/cancellation binding, current page role bindings/cancellation binding and all role bindings/cancellation binding.
Preferably in embodiment, in step S2, a kind of base class of the role's of inquiry paging is provided, the major key set bindingSet that its main private variable comprising is all roles and resource binding and all the Boolean type variable allSelected of binding/cancel all binding, binding/cancellation bindings that user carries out at front page layout is reacted to the variation of bindingSet and allSelected.
Preferably in embodiment, the operation of the single role that user carries out on foreground and resource binding/cancellation binding and current page role and resource binding/cancellation binding can cause the variation of bindingSet, the role who inquires all realizes the variation that can cause allSelected with resource binding/cancellation bindings, in page management BEAN, to, according to above-mentioned variation, reset role's major key set bindingSet that need to be tied to resource.
Preferably in embodiment, the described bindingSet generating in page management BEAN, when being updated to database, need to compare with role's list of primary keys roleIds of resource binding.
Preferably, in embodiment, the role's major key all existing in bindingSet and roleIds, need to remove these major keys from bindingSet.
Preferably in embodiment, in roleIds, exist and non-existent role's major key in bindingSet, need to be by corresponding role and the resource unbind relation of these major keys.
Preferably in embodiment, in bindingSet, exist and non-existent role's major key in roleIds, corresponding role and the resource of these major keys need to be set up to binding relationship.
Compared with prior art, beneficial effect of the present invention is:
By light click one button or link, bindings is bound/cancelled to disposable realization by multipage role list and the resource of the condition that conforms to inquiring.
Accompanying drawing explanation
Fig. 1 is a kind of resource multipage distribution method process flow diagram based on AJAX provided by the invention;
Fig. 2 is to be role's major key set bindingSet change figure that the resource multipage distribution method that the present invention is based on Ajax is tied to resource;
Fig. 3 be the resource multipage distribution method that the present invention is based on Ajax in management BEAN, obtain need to role's major key set bindingSet of resource binding;
Fig. 4 is that the resource multipage distribution method that the present invention is based on Ajax need to be updated to database with role's major key set bindingSet of resource binding;
Fig. 5 A to Fig. 5 E, for realizing an object lesson of the present invention, is that bulletin is distributed to personal account, and E-mail address is the identity information of sign personal account.Wherein, Fig. 5 A, i.e. querying individual account; Fig. 5 B, the personal account paging list inquiring; Fig. 5 C-1 and Fig. 5 C-2, click " choosing entirely " page design sketch; Fig. 5 D-1 and Fig. 5 D-2, click " Quan Buxuan " page design sketch; With Fig. 5 E, be about to bulletin the distribution of personal account is updated to database.
Embodiment
Below in conjunction with accompanying drawing, to the present invention is above-mentioned, be described in more detail with other technical characterictic and advantage.
The present invention is a kind of resource multipage distribution method based on AJAX, and it is the web technologies based on AJAX, and resource and the polygonal look inquiring are realized to binding or cancelled bindings.
The invention provides a kind of base class of the role's of inquiry paging, the major key that it main private variable comprising is all roles and resource binding (or can represent field and the structure of role's uniqueness, as follows) set bindingSet and the Boolean type variable allSelected that all binding/cancel alls are bound.The single role who carries out on foreground as user and resource binding/cancellation binding and current page role can cause bindingSet variation with resource binding/cancellation bindings.When the role who inquires all realizes the variation that can cause allSetected with resource binding/cancellation bindings.Therefore, binding/cancellation bindings that user realizes on foreground directly causes the variation of bindingSet and allSelected, then the management BEAN by the page newly gathers bindingSet by this reacting condition to role's major key that need to be tied to resource, finally by submit operation, is updated to database or other storage entity.
Above-mentioned front page layout adopts AJAX technology, the operation that user carries out, for example: certain role and resource binding, certain role and resource are cancelled binding; Certain page of role and resource binding, certain page of role and resource are cancelled binding; All page roles and resource binding and all page role cancel and binding with resource, the change of all can dynamic reflection arriving bindingSet.
BindingSet described in the resource multipage distribution method of the invention described above based on AJAX, its finite element set comprise from data base querying to role's major key of all and resource binding, by described finite element set, can determine whether the check box control original state of whether binding with resource corresponding to single role is chosen; Through user, operate role and resource binding/cancellation bindings, in the management BEAN of the page, obtain need to role's major key set bindingSet of resource binding, and this set is compared with role's list roleId of known resource binding, there is following several situation:
The role's major key all existing in bindingSet and roleIds need to remove these role's major keys from bindingSet set;
In roleIds, exist and non-existent role's major key in bindingSet, need to be by corresponding role and the resource unbind relation of these role's major keys;
In bindingSet, exist and non-existent role's major key in roleIds, corresponding role and the resource of these role's major keys need to be set up to binding relationship.
Above-mentioned situation can be by embodying in table one: whether table one exists mutual relationship operation table for the present invention is based in the resource multipage distribution method bindingSet of Ajax major key in role's major key and role's list of primary keys of having bound.
Table one
To sum up, consulting Fig. 1, is a kind of resource multipage distribution method process flow diagram based on AJAX provided by the invention, and its concrete steps are as follows:
Step S1: bindingSet is carried out to initialization setting, its initial sets is made as to role's major key of having bound with resource in database;
Step S2: binding/cancellation bindings that user carries out at front page layout is reacted to the variation of bindingSet;
Step S3: user carries out submit operation, will newly gather bindingSet and be updated to database or other storage entity.
Below above-mentioned steps is elaborated:
First consult Fig. 2, for the present invention is based on the resource multipage distribution method of Ajax, be tied to role's major key set bindingSet change figure of resource, as shown in the figure:
First, to carry out initialization setting to bindingSet, its initial sets is made as to role's major key of having bound with resource in database, by this initial sets, can determines whether check box chooses to show whether the role who checks out binds with resource, inquire qualified role's list, the corresponding check box of each role, arranges the initial value of check box, and this can retrieve at bindingSet by major key, if can retrieve, this check box is " choosing " state; Otherwise this check box is " not choosing " state.
Secondly, user is tied to resource for role bindings/cancellation action need at front page layout is updated in set bindingSet, described binding/cancellation binding comprises single role bindings/cancellation binding, current page role bindings/cancellation binding and all role bindings/cancellation binding, and this process will be described in detail in Fig. 3.
Finally, also will from bindingSet set, remove the role's major key with resource binding, this process will be described in detail in Fig. 4
Refer to shown in Fig. 3, for the resource multipage distribution method that the present invention is based on Ajax in management BEAN, obtain need to role's major key set bindingSet of resource binding; Processing page operation has a public class, in such, include two private variables, one is that user carries out routine operation and causes role's major key set bindingSet change and resource binding as the binding of single role bindings/cancellation and the complete not selection operation of the full choosing/page of page, another one variable is the Boolean type variable allSelected that the binding of all bind/cancel all causes variation, and its initial value is false.User is reacted directly into the variation of gathering bindingSet and variable allSelected in this public class to the operation of front page layout.But finally the two will be reacted to and need to newly gather bindingSet with role's major key of resource binding, and it can be processed by implementation method function in page management BEAN, what Fig. 3 described is the idiographic flow of these class methods.
Refer to shown in Fig. 3, first the null set bindingSet of role's major key type of initialization; Then by the public class of definition, obtain the Boolean type variable allSelected that need to cause variation with role's major key set bindingSet and whole binding/cancel all binding of resource binding that foregrounding causes variation; Secondly according to querying condition, inquiry obtains role's list of primary keys, and sets the vernier it of this list of traversal; Again secondly by vernier it traversal of lists, if role's Major key roleId of corresponding node is present in bindingSet set or allSelected is true (i.e. all binding), is about to roleId and adds role's major key that new needs bind to and gather in temp temporarily; Finally by temp assignment to bindingSet, return really and need to newly gather bindingSet with role's major key of resource binding.
Please refer to Fig. 4, for the present invention is based on the resource multipage distribution method of Ajax, need to be updated to database with role's major key set bindingSet of resource binding.In Fig. 3 by the management BEAN corresponding with the page obtain really need to role's major key set of resource binding, but user, bind/cancel in bindings process, the role that may need to bind resource is in fact with resource binding.Like this will be to the processing of classifying of role corresponding to major key in bindingSet set.
As shown in Figure 4, first according to the method for Fig. 3 obtain really need to role's major key set bindingSet of resource binding, then inquiry obtain existing with role's list of primary keys of resource binding, and the vernier it of this list of setting traversal, secondly by vernier it traversal of lists, if role's Major key roleId of corresponding node is present in bindingSet set, roleId is removed from bindingSet, otherwise by corresponding role and the resource unbind relation of roleId; Finally the role that in bindingSet, all major keys are corresponding is all set up to binding relationship with resource.BindingSet set be role's major key and inquire have respectively " existence " and " not existing " two kinds of situations with role's major key of resource binding, combine and just have four kinds of situations, such as the role's major key existing in bindingSet set, also be present in role's list of primary keys of having bound, the operation of implementing is that this major key is removed from bindingSet set, as shown in Table 1.
Fig. 5 A to Fig. 5 E, for realizing an object lesson of the present invention, is that bulletin is distributed to personal account, and E-mail address is the identity information of sign personal account.Comprise Fig. 5 A, i.e. querying individual account; Fig. 5 B, the personal account paging list inquiring; Fig. 5 C-1 and Fig. 5 C-2, click " choosing entirely " page design sketch; Fig. 5 D-1 and Fig. 5 D-2, click " Quan Buxuan " page design sketch; With Fig. 5 E, be about to bulletin the distribution of personal account is updated to database.
This embodiment distributes to personal account by bulletin, and E-mail address is the identity information of sign personal account.Fig. 5 A fills in personal account querying condition, what is not filled out, represent that inquiry is all, obtain Fig. 5 B personal account paging list, in figure, show and find altogether two pages of 14 records, article one, record check box above is chosen, represent that bulletin has been assigned to this personal account, click " choosing entirely " link on the page, effect is as Fig. 5 C-1 and Fig. 5 C-2, two pages of all records check box above is all chosen, " Quan Buxuan " if on click page link, as Fig. 5 D-1 and Fig. 5 D-2, all records of two pages check box above all becomes not selected state, click " determining " button of page lower end, turn back to bulletin administration page, click data manipulation the first row on the page " submit to and revise " as Fig. 5 E, bulletin is updated to database to the distribution of personal account.
It should be noted that, the present invention is directed to the embodiment that resource is distributed to role and set forth, vice versa, is about to role assignments to multipage resource.
In sum, the invention provides a kind of resource multipage distribution method based on AJAX, whether it chooses to realize binding/cancellation bindings of itself and resource by the check box corresponding with each role; By clicking the button of " page is choosing entirely ", " page does not select entirely " in the page or linking binding/cancellation bindings that disposable batch is realized current page role and resource; By clicking the button of " choosing entirely ", " Quan Buxuan " in the page or linking disposable batch, realize all multipage roles of the condition that conforms to and the binding/cancellation bindings of resource inquiring.Be that the present invention has realized and all realizes binding or cancel binding with resource the multipage role who inquires is disposable.
More than explanation is just illustrative for the purpose of the present invention, and nonrestrictive, those of ordinary skills understand; in the situation that do not depart from the spirit and scope that following claims limit, can make many modifications, change; or equivalence, but all will fall within the scope of protection of the present invention.