Summary of Lookup

Source: Internet
Author: User

Today, I made a new look at the lookup page and process design of the experiment project.

The lookup: Lookup page displays a list of objects provided to other entities. For example, to associate an experiment course with an experiment project, first, there is a page on which the lab course is associated with an experiment project. Then, you can click "add" on this page to open the lookup page, the experiment project is not included in the previous experiment course. The administrator can select some items and click "add". The lookup page returns a string consisting of the selected items, then the original page can be added according to this string. Note that when you open the lookup page, the previous page will give it a query condition where (string) used to filter out the experiment projects that can be selected

Note that there is only one lookup! No matter which entity it provides for viewing, it uses that page, which increases the difficulty of project development and the reusability of code. If you want to add a lookup later, therefore, it is convenient to add and modify codes without adding too many other pages and codes.

Next I will perform the following operations: Taking the associated experiment project of the experiment course as an Example

1. Add "associate experiment Project"

The Lab Course Management page is mainly a dategrid, which adds an additional operation column to this dategrid

Newcol = coursedbgrid. addcol (); newcol. settitlestring ("associate experiment project"); newcol. setcoltype (Const. bs_crl_col_adddataoperate); newcol. setcolcontroltype (Const. bs_crl_link); newcol. setcellfun ("docourseitemr ()");

When this column is clicked, The js method will be called.

Function docourseitemr () {// open the experiment project var fromobj ={}; fromobj associated with the experiment course. id = coursedbgrid. dogetcellvalue (0); // alert (fromobj. ID); p. openparentdlg ("lookup_itemforcourse", "associate experiment Project", 690,420, fromobj, "item", "courseitemini", "& in_courseid =" + fromobj. ID, window, true, true ,"","");}

After this js method is called, the selected Lab Course ID is obtained, a new dialog is opened, and the do_courseitemini method of BSID = "item" (corresponding Javabean is bsitem) is executed.

At the same time, an in_courseid parameter is passed to the background. Note that fromobj is passed to the next page, which means that the selected course Id can be obtained on the next page. This is very important, note how the ID is passed here

2. Compile the do_courseitemini Method

/*** <P> * method name: do_courseitemini * </P> * <p> * method description: lab project page associated with the lab course * </P> * <p> * input parameter: bsobject m_bs: BS framework Business Object * </P> * <p> * output parameter: bsobject: BS framework Business Object * </P> */Public bsobject do_courseitemini (bsobject m_bs) throws exception {m_bs.setcurpage ("system/Course/courseitem. JSP "); string courseid = (string) m_bs.getprivatemap (). get ("in_courseid"); m_bs.setprivatevalue ("lookup_coursename", wdlabstatic. coursemap. get (courseid ). getname (); sqlexecute sqlhelper = new sqlexecute (); try {bsitemdbmang itemdb = new bsitemdbmang (sqlhelper, m_bs); // SQL = "select T. item_id, T. item_name, T. item_state, T. item_type, T. item_desc from t_exp_item t where T. item_id is not null and T. item_state = '1' and T. item_id in // (select t2.item _ id from t_course_item_r T2 where T. item_id = t2.item _ id and t2.course _ id = '5d8026c12e9d5c4e009aa4c3cc75a629 ') order by T. item_id "string where =" and T. item_id in (select t2.item _ id from t_course_item_r T2 where T. item_id = t2.item _ id and t2.course _ id = '"+ courseid +"') "; arraylist <itempojo> List = itemdb. getitemlist (where); this. _ setcourseitemdatagrid (m_bs, list); // SQL = "select T. item_id, T. item_name, T. item_state, T. item_type, T. item_desc from t_exp_item t where T. item_id is not null and T. item_state = '1' and T. item_id not // In (select t2.item _ id from t_course_item_r T2 where T. item_id = t2.item _ id and t2.course _ id = '5d8026c12e9d5c4e009aa4c3cc75a629 ') order by T. item_id "string itemwhere =" and T. item_id not in (select t2.item _ id from t_course_item_r T2 where T. item_id = t2.item _ id and t2.course _ id = '"+ courseid +"') "; m_bs.setprivatevalue (" itemwhere ", itemwhere);} catch (exception EP) {EP. printstacktrace (); throw EP;} finally {sqlhelper. close ();} return m_bs ;}

This method first gets the passed parameter courseid, that is, the selected course Id. This is very important. Based on this ID, we can get the corresponding Course name in coursemap in wdlabstatic, instead of querying the database

Secondly, we can obtain two where query conditions based on this courseid: one is to obtain the experiment project associated with this course according to this courseid, and the other is to obtain the experiment project not associated with it according to this courseid.

Among them, the latter is very important. It will not execute the query first. Only when lookup is enabled will the query be passed and executed. This process is like this:

Courseitem. jsp: displays the page of an experiment project associated with an experiment course. The "add" button is displayed on the page to show the effect:

 

This page contains a hidden text: <BS: text type = "hidden" name = "itemwhere"/>

It stores the second where query condition mentioned earlier. Because the data volume is large, the get method cannot be used for transmission. It can only be post.

Add js method, that is, the event triggered after clicking "add"

VaR fobj = thisdlg. inobj;

    function addItem(){        var tObj = {};        tObj.itemwhere = $("itemwhere").value;        tObj.id=fObj.id;        //alert(tObj.id);        //alert(tObj.itemwhere);        doItemLookup(tObj.itemwhere,tObj.id,"addItemRet");    }

Note the first sentence: var fobj = thisdlg. inobj; here, fobj is the fromobj, which contains an ID, that is, the selected courseid!

This js method is to get the where and get an ID at the same time. Next we will introduce the transfer process of this ID, and then we will call another js method doitemlookup.

I defined it in wdlookup. js. This method is used independently to improve code reusability and reduce coupling.

Function doitemlookup (where, ID, retfun) {var fromobj ={}; fromobj. where = where; fromobj. id = ID; p. openparentdlg ("wdlookup_item", "Select experiment Project", 700,420, fromobj, "item", "itemlookupini", "", window, true, false, retfun );}

Execution of this JS: first obtain the where and ID parameters, put them in a new object fromobj, and open a new dialog. This new page is the lookup page.

Note that the third method is the callback function, that is, the method executed after the form is closed.

3. Compile itemlookupini

/***** <P> * method name: do_itemlookupini * </P> * <p> * method description: initialize the associated experiment project page * </P> * <p> * input parameter: bsobject m_bs: BS framework Business Object * </P> * <p> * output parameter: bsobject: BS framework Business Object * </P> */Public bsobject do_itemlookupini (bsobject m_bs) throws exception {m_bs.setcurpage ("labbase/item/lookup. JSP "); // note that the path is set to sqlexecute sqlhelper = new sqlexecute () starting from the root directory; try {string where = (string) m_bs.getprivatemap (). get ("itemwhere"); bsitemdbmang itemdb = new bsitemdbmang (sqlhelper, m_bs); arraylist <itempojo> itemlist = itemdb. getitemlist (where); this. _ setlookupdatagrid (m_bs, itemlist); // set the experiment project list on the lookup page} catch (exception e) {e. printstacktrace (); throw E;} finally {sqlhelper. close ();} return m_bs ;}

 

This method first obtains the previous string where = (string) m_bs.getprivatemap (). Get ("itemwhere"); this is the filtering condition. Based on this filtering, other experiment projects that are not associated are obtained.

Query and get an itemlist. Put this list in dategrid!

 

After selecting a few items, you can get a string consisting of the selected items, calling a js method in Lookup

    function addItems() {        var keyStr=ItemLookUpDataGrid.getSelectKey();        if(keyStr==""&&keyStr==null){            keyStr="T";        }        var tObj = {};        tObj.keyStr = keyStr;        tObj.id=fObj.id;        //alert(tObj.id);        alert(tObj.keyStr);        thisDlg.returnObj = tObj;        thisDlg.closeDlg();    }

The first sentence is to get the string. Note that this string may be null or null. If it is not processed, it is directly returned to the original form, a null pointer exception will be reported during the query.

Then we get fobj. Id. Like the previous one, fobj is the ID passed in the previous page or the selected courseid.

After keystr and ID are set to the tobj object, you can return thisdlg. returnobj = tobj as the returned object;

The last step is to close the lookup page.

 

4. Callback Method

As mentioned above, there is a callback method called after the lookup page is closed. Here is a js method.

    function addItemRet(r_obj, i_obj){        var keyStr = r_obj.keyStr;        var courseId=r_obj.id;        if(keyStr!=""&&keyStr!=null){            //doRefresh("CLASSMANG","addItem",true,"","&in_keyStr="+keyStr,"showItemRet");        }    }

It is defined in courseitem. in JSP, here is the end of the entire process. r_obj is the returned object on the lookup page above, where the string (selected item) and ID are saved, which is the first selected Lab Course.

Now we have returned the result, and then we have a judgment. If the string is valid, we can call the zero-Refresh Method for zero refresh, after refresh, the original association is added and then added.

 

Summary:

This process is much clearer after summary. The reason for doing so is to ensure that there is only one lookup page! This is the real project development!

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.