KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dlog4j > tags > EditCategoryTag


1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */

16 package dlog4j.tags;
17
18 import javax.servlet.jsp.JspException JavaDoc;
19 import javax.servlet.jsp.PageContext JavaDoc;
20
21 import net.sf.hibernate.Session;
22 import dlog4j.formbean.CategoryForm;
23
24 /**
25  * 编辑日记分类的标签库(用于cat_list.jsp)
26  * @author Liudong
27  */

28 public class EditCategoryTag extends DlogBaseTag {
29
30     String JavaDoc scope = "session";
31     String JavaDoc catId = null;
32     
33     public int doStartTag() throws JspException JavaDoc {
34         int iScope = PageContext.SESSION_SCOPE;
35         if("request".equalsIgnoreCase(scope))
36             iScope = PageContext.REQUEST_SCOPE;
37         CategoryForm catForm = (CategoryForm)pageContext.getAttribute(id,iScope);
38         if(catForm==null) {
39             int rid = -1;
40             try {
41                 rid = Integer.parseInt(catId);
42             }catch(Exception JavaDoc e) {}
43             if(rid == -1) {
44                 try {
45                     rid = Integer.parseInt(pageContext.getRequest().getParameter("cat_id"));
46                 }catch(Exception JavaDoc e) {}
47             }
48             if(rid!=-1) {
49                 Session ssn = null;
50                 try {
51                     ssn = getSession();
52                     catForm = (CategoryForm)ssn.load(CategoryForm.class,new Integer JavaDoc(rid));
53                     pageContext.setAttribute(id,catForm,iScope);
54                 } catch (Exception JavaDoc e) {
55                     throw new JspException JavaDoc(e);
56                 }finally {
57                     try {
58                         closeSession(ssn);
59                     }catch(Exception JavaDoc e) {}
60                 }
61             }
62         }
63         return SKIP_BODY;
64     }
65     public int doEndTag() throws JspException JavaDoc {
66         release();
67         return EVAL_PAGE;
68     }
69     public void release() {
70         scope = "session";
71         catId = null;
72     }
73     public String JavaDoc getScope() {
74         return scope;
75     }
76     public void setScope(String JavaDoc scope) {
77         this.scope = scope;
78     }
79     public String JavaDoc getCatId() {
80         return catId;
81     }
82     public void setCatId(String JavaDoc catId) {
83         this.catId = catId;
84     }
85 }
86
Popular Tags