KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > wstore > RequestTypeTag


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Smart Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.wstore;
15
16 import java.util.*;
17 import java.sql.*;
18 import javax.servlet.http.*;
19 import javax.servlet.jsp.*;
20 import javax.servlet.jsp.tagext.*;
21
22 import org.apache.ecs.xhtml.*;
23 import org.apache.log4j.Logger;
24
25 import org.compiere.util.Env;
26 import org.compiere.util.DB;
27
28 /**
29  * Request Type Tag.
30  * Create Drop Down List with valid values
31  *
32  * <cws:requestType/>
33  *
34  * @author Jorg Janke
35  * @version $Id: RequestTypeTag.java,v 1.7 2003/06/20 14:45:18 jjanke Exp $
36  */

37 public class RequestTypeTag extends TagSupport
38 {
39     /** Logger */
40     private Logger log = Logger.getLogger (getClass());
41
42     /**
43      * Start Tag
44      * @return SKIP_BODY
45      */

46     public int doStartTag()
47     {
48         JspWriter out = pageContext.getOut();
49         select select = getRequestType();
50         select.output(out);
51         //
52
return (SKIP_BODY);
53     } // doStartTag
54

55     /**
56      * Create Select List
57      * @return select list
58      */

59     private select getRequestType()
60     {
61         select select = new select(RequestServlet.P_REQUESTTYPE_ID, getOptions());
62         select.setID("ID_" + RequestServlet.P_REQUESTTYPE_ID);
63         return select;
64     } // getRequestType
65

66     /**
67      * Get the Request Type options
68      * @return array of options
69      */

70     private option[] getOptions()
71     {
72         Properties ctx = JSPEnv.getCtx((HttpServletRequest)pageContext.getRequest());
73         int AD_Client_ID = Env.getContextAsInt(ctx, "#AD_Client_ID");
74         if (AD_Client_ID == 0)
75             log.error("getOptions - AD_Client_ID not found");
76         else
77             log.info("getOptions - AD_Client_ID=" + AD_Client_ID);
78         ArrayList list = new ArrayList();
79         //
80
String JavaDoc sql = "SELECT R_RequestType_ID, Name FROM R_RequestType "
81             + "WHERE AD_Client_ID=? AND IsActive='Y' AND IsSelfService='Y' "
82             + "ORDER BY IsDefault DESC, Name";
83         PreparedStatement pstmt = null;
84         try
85         {
86             pstmt = DB.prepareStatement(sql);
87             pstmt.setInt(1, AD_Client_ID);
88             ResultSet rs = pstmt.executeQuery();
89             while (rs.next())
90             {
91                 option o = new option (rs.getString(1));
92                 o.addElement(rs.getString(2));
93                 list.add(o);
94             }
95             rs.close();
96             pstmt.close();
97             pstmt = null;
98         }
99         catch (Exception JavaDoc e)
100         {
101             log.error("getOptions", e);
102         }
103         finally
104         {
105             try
106             {
107                 if (pstmt != null)
108                     pstmt.close ();
109             }
110             catch (Exception JavaDoc e)
111             {}
112             pstmt = null;
113         }
114
115         // Return to Array and return
116
option options[] = new option [list.size()];
117         list.toArray(options);
118         log.debug("getOptions = #" + options.length);
119         return options;
120     } // getOptions
121

122 } // RequestTypeTag
123
Popular Tags