1 16 package dlog4j.tags; 17 18 import javax.servlet.jsp.JspException ; 19 import javax.servlet.jsp.PageContext ; 20 21 import net.sf.hibernate.Session; 22 import dlog4j.formbean.UserForm; 23 24 28 public class GetUserTag extends DlogBaseTag { 29 30 String scope = "session"; 31 String userId = null; 32 33 public int doStartTag() throws JspException { 34 int iScope = PageContext.SESSION_SCOPE; 35 if("request".equalsIgnoreCase(scope)) 36 iScope = PageContext.REQUEST_SCOPE; 37 UserForm userForm = (UserForm)pageContext.getAttribute(id,iScope); 38 if(userForm==null) { 39 int rid = -1; 40 try { 41 rid = Integer.parseInt(userId); 42 }catch(Exception e) {} 43 if(rid == -1) { 44 try { 45 rid = Integer.parseInt(pageContext.getRequest().getParameter("userid")); 46 }catch(Exception e) {} 47 } 48 if(rid!=-1) { 49 Session ssn = null; 50 try { 51 ssn = getSession(); 52 userForm = (UserForm)ssn.load(UserForm.class,new Integer (rid)); 53 pageContext.setAttribute(id,userForm,iScope); 54 } catch (Exception e) { 55 throw new JspException (e); 56 }finally { 57 try { 58 closeSession(ssn); 59 }catch(Exception e) {} 60 } 61 } 62 } 63 return SKIP_BODY; 64 } 65 public int doEndTag() throws JspException { 66 release(); 67 return EVAL_PAGE; 68 } 69 public void release() { 70 scope = "session"; 71 userId = null; 72 } 73 public String getScope() { 74 return scope; 75 } 76 public void setScope(String scope) { 77 this.scope = scope; 78 } 79 public String getUserId() { 80 return userId; 81 } 82 public void setUserId(String userId) { 83 this.userId = userId; 84 } 85 public void setUserId(int userId) { 86 this.userId = String.valueOf(userId); 87 } 88 public void setUserId(Integer userId) { 89 this.userId = userId.toString(); 90 } 91 } 92 | Popular Tags |