Dynamic list based on hibernate

Source: Internet
Author: User

Use Hibernagte to achieve the following functions:

That is, select the item below to be explicit, and the top list is explicit.

Specific implementation:

STRUTS2 implementation:

<table width= "100%" cellspacing= "1" class= "l_table" >


<tr class= "L_title" >


<s:iterator value= "Showitems" >


<td>


<s:property value= "value"/>


</td>


</s:iterator>


</tr>


<s:iterator value= "Pager.result" status= "St" id= "list" >


<tr class= "L_tr" >


<s:iterator value= "list" status= "St1" >


<td>


<s:if test= "#st1. Count==1" >


<input type= "checkbox" vlaue= "<s:property value=" #list [0] "/>"/>


</s:if>


<s:elseif test= "#st1. count==2" >


<a href= "#"


onclick= "Openwindow (' Customer.action?cusid=<s:property value=" #list [0] "/>", 800,600, ' CusW <s:property value= "#list [0]"/> ")" ><s:property/>


</a>


</s:elseif>


<s:else>


<s:property/>


</s:else>


</td>


</s:iterator>


</tr>


</s:iterator>


</table>





<table width= "100%" algin= "center" id= "SELECTT" >


<tr>


<td align= "center" >


<b> Display Items </b>


</td>


</tr>


<tr>


<td>


<s:iterator value= "Selectitems" >


<s:property value= "value"/>


<input type= "checkbox" value= "<s:property value=" key "/>"/>


</s:iterator>


</td>


</tr>


<tr>


<td align= "center" >


<input type= "button" id= "Btn_refresh" value= "Update"/>


</td>


</tr>


</table>





public String Execute () throws Exception {


page = page = null? 1:page;


pageSize = PageSize = null? 10:pagesize;


pager = new page<object[]> ();


Pager.setpageno (page);


pager.setpagesize (pageSize);


Pager.setstyletype (2);


pager.settarget ("list_customers.asp?pagesize=" + pageSize);


/**//* Custom List item * *


Boolean isexistcookie = false;


cookie[] cookies = Getrequest (). GetCookies ();


for (Cookie cookie:cookies) {


if (Cookie.getname (). Equals ("Showitemsstr")) {


//Cookie exists


Isexistcookie = true;


if (showitemsstr!= null &&!showitemsstr.trim (). Equals ()) {


//Refresh Cookie


Cookie.setvalue (SHOWITEMSSTR);


Cookie.setmaxage (60 * 60 * 24 * 30);


GetResponse (). Addcookie (cookie);


} else {


//read from Cookie


showitemsstr = Cookie.getvalue ();


        }


break;


      }


    }


//cookie does not exist


if (!isexistcookie) {


if (showitemsstr!= null &&!showitemsstr.trim (). Equals ()) {


//Create Cookie


cookie C = new Cookie ("Showitemsstr", showitemsstr);


C.setpath ("/");


C.setmaxage (60 * 60 * 24 * 30);


GetResponse (). Addcookie (c);


      }


    }


if (showitemsstr = null | | | Showitemsstr.trim (). Equals ("")) {


//Is NULL, default


showitemsstr = "Cusnation|cuscity|custelnum|cusemail";


    }


Showitemsstr = "id|cusname|" + showitemsstr;//ID cusname must be


Showitems = Getmapfromstr (SHOWITEMSSTR);


pager = customermanager.getcustomers (pager, SHOWITEMSSTR);





Selectitems = Getcusstringmap ();


selectitems.remove ("id");


selectitems.remove ("Cusname");


Searchitems = Getcusstringmap ();


searchitems.remove ("id");


return SUCCESS;


  }


private map<string, string> getmapfromstr (String str) {


str = Str.trim ();


if (str = NULL | | str.equals (""))


return null;


map<string, string> Map = new linkedhashmap<string, string> ();


string[] STRs = Str.split ("\\|");


for (String s:strs) {


Map.put (S, Getcusstringmap (). get (s));


}


return map;


  }





private map<string, string> Getcusstringmap () {


map<string, string> Map = new linkedhashmap<string, string> ();


map.put ("id", "serial number");


map.put ("Cusname", "Customer Name");


map.put ("Cusemail", "e-mail");


/* Omit specific Item * * *


return map;


  }





public page<object[]> Getlinkmans (page<object[]> Page, String showitemsstr) {


String hql = "Select" + Showitemsstr.trim (). ReplaceAll ("\\|", ",")


+ "from Linkman";


Page.setautocount (FALSE);


int totalcount = linkmandao.sum ("SELECT count (*) from Linkman")


. Intvalue ();


Page.settotalcount (TotalCount);


Page.setresult (Linkmandao


. Find (HQL, Page.getfirst (), page.getpagesize ());


return page;


  }

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.