1 16 package dlog4j.tags; 17 18 import java.sql.SQLException ; 19 import java.util.List ; 20 21 import javax.servlet.jsp.JspException ; 22 23 import net.sf.hibernate.HibernateException; 24 import net.sf.hibernate.Session; 25 import dlog4j.ParamManager; 26 import dlog4j.SiteManager; 27 import dlog4j.UserManager; 28 import dlog4j.formbean.SiteForm; 29 30 34 public class MemberTag extends DlogBaseTag { 35 36 public final static String USERS_PER_PAGE = "USERS_PER_PAGE"; 37 38 int count = -1; 39 int page = -1; int role = -2; 41 String usersPageId = MemberTei.PER_COUNT; 42 String pageCountId = MemberTei.PAGE_COUNT; 43 String userCountId = MemberTei.USER_COUNT; 44 String curPageId = MemberTei.CUR_PAGE_COUNT; 45 boolean query = true; 46 47 public int doEndTag() throws JspException { 48 release(); 49 return EVAL_PAGE; 50 } 51 public void release() { 52 count = -1; 53 page = -1; role = -2; 55 } 56 59 public int doStartTag() throws JspException { 60 Session session = null; 61 List users = null; 62 String query_key = null; 63 if(query) 64 query_key = getParameter("query"); 65 try { 66 session = getSession(); 67 SiteForm site = SiteManager.getCurrentSite(pageContext.getRequest()); 68 int userCount = UserManager.getUserCount(session,site,role,query_key); 70 pageContext.setAttribute(userCountId,new Integer (userCount)); 71 int usersPage = ParamManager.getIntParam(session,site,USERS_PER_PAGE,10); 73 pageContext.setAttribute(usersPageId,new Integer (usersPage)); 74 int pageCount = (userCount / usersPage) + (((userCount % usersPage)>0)?1:0); 76 pageContext.setAttribute(pageCountId,new Integer (pageCount)); 77 pageContext.setAttribute(curPageId, new Integer (page)); 79 int from = page-1; 81 if(from<0) 82 from = 0; 83 if(from>pageCount) 84 from = pageCount; 85 from *= usersPage; 86 int uc = (count==-1)?usersPage:count; 87 users = UserManager.listUsers(session,site,from,uc,query_key); 88 pageContext.setAttribute(id, users); 89 } catch (SQLException e) { 90 throw new JspException (e); 91 } catch (HibernateException e) { 92 throw new JspException (e); 93 } finally { 94 try { 95 closeSession(session); 96 } catch (Exception e) { 97 } 98 } 99 return SKIP_BODY; 100 } 101 102 public int getCount() { 103 return count; 104 } 105 106 public void setCount(int i) { 107 count = i; 108 } 109 110 public int getPage() { 111 return page; 112 } 113 public void setPage(int page) { 114 this.page = page; 115 } 116 public void setPage(String page) { 117 this.page = Integer.parseInt(page); 118 } 119 public void setPage(Integer page) { 120 this.page = page.intValue(); 121 } 122 public String getPageCountId() { 123 return pageCountId; 124 } 125 public void setPageCountId(String pageCountId) { 126 this.pageCountId = pageCountId; 127 } 128 public String getUserCountId() { 129 return userCountId; 130 } 131 public void setUserCountId(String userCountId) { 132 this.userCountId = userCountId; 133 } 134 public String getUsersPageId() { 135 return usersPageId; 136 } 137 public void setUsersPageId(String usersPageId) { 138 this.usersPageId = usersPageId; 139 } 140 public int getRole() { 141 return role; 142 } 143 public void setRole(int role) { 144 this.role = role; 145 } 146 public String getCurPageId() { 147 return curPageId; 148 } 149 public void setCurPageId(String curPageId) { 150 this.curPageId = curPageId; 151 } 152 public boolean isQuery() { 153 return query; 154 } 155 public void setQuery(boolean query) { 156 this.query = query; 157 } 158 } 159 | Popular Tags |