~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to j2ee/samples/samples_src/CustomerCMP/CustomerCMP-war/web/searchCustomer.jsp

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!--
 
2
  Copyright (c) 2007, Sun Microsystems, Inc. All rights reserved.
 
3
 
 
4
  Redistribution and use in source and binary forms, with or without
 
5
  modification, are permitted provided that the following conditions are met:
 
6
 
 
7
  * Redistributions of source code must retain the above copyright notice,
 
8
    this list of conditions and the following disclaimer.
 
9
 
 
10
  * Redistributions in binary form must reproduce the above copyright notice,
 
11
    this list of conditions and the following disclaimer in the documentation
 
12
    and/or other materials provided with the distribution.
 
13
 
 
14
  * Neither the name of Sun Microsystems, Inc. nor the names of its contributors
 
15
    may be used to endorse or promote products derived from this software without
 
16
    specific prior written permission.
 
17
 
 
18
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
19
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
20
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
21
  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 
22
  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
23
  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
24
  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
25
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
26
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
27
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 
28
  THE POSSIBILITY OF SUCH DAMAGE.
 
29
-->
 
30
 
 
31
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
 
32
<fmt:setBundle basename="LocalStrings"/>
 
33
 
 
34
<%@ page language="java" %>
 
35
<%@ page import="java.util.ArrayList" %>
 
36
<%@ page import="java.util.Collection" %>
 
37
<%@ page import="javax.ejb.ObjectNotFoundException" %>
 
38
<%@ page import="javax.naming.InitialContext" %>
 
39
<%@ page import="enterprise.customer_cmp_ejb.persistence.Customer" %>
 
40
<%@ page import="enterprise.customer_cmp_ejb.ejb.session.*" %>
 
41
<%@ page import='java.util.*' %>
 
42
 
 
43
<html>
 
44
 
 
45
<head><title><fmt:message key="cmp_demo_title"/></title></head>
 
46
<body bgcolor="white">
 
47
<center>
 
48
<h2><fmt:message key="cmp_demo_title"/> </h2>
 
49
 
 
50
<fmt:message key="search_for_customer"/> :
 
51
<p>
 
52
    <form method="get" action="/customer/searchCustomer.jsp">
 
53
    Search by 
 
54
    <select name="searchCriteria">
 
55
      <option value="customerID" selected><fmt:message key="customer_id"/> 
 
56
      <option value="lastName"><fmt:message key="last_name"/> 
 
57
      <option value="firstName"><fmt:message key="first_name"/> 
 
58
    </select>
 
59
    <input type="text" name="searchText" size="25">
 
60
    <p>
 
61
    <input type="submit" value=<fmt:message key="search"/> >
 
62
    </form>
 
63
 
 
64
<%
 
65
String text = request.getParameter("searchText");
 
66
String criteria = request.getParameter("searchCriteria");
 
67
 
 
68
if (text != null && !"".equals(text)) {
 
69
    try {
 
70
        InitialContext ic = new InitialContext();
 
71
        Object o = ic.lookup("java:comp/env/CustomerSessionLocal");
 
72
        CustomerSessionLocal custSession = (CustomerSessionLocal) o;
 
73
 
 
74
        List customers=new ArrayList(); //creating empty list handles any errors gracefully.
 
75
        if ("customerID".equals(criteria)) {
 
76
            Customer customer = custSession.searchForCustomer(text);
 
77
            if(customer!=null){
 
78
                customers.add(customer);
 
79
            }
 
80
        }         
 
81
        else if ("lastName".equals(criteria)) {
 
82
          customers = custSession.findCustomerByLastName(text);
 
83
        } else if ("firstName".equals(criteria)) {
 
84
          customers = custSession.findCustomerByFirstName(text);
 
85
        } else {
 
86
        }
 
87
  
 
88
 
 
89
%>
 
90
<fmt:message key="results"/> : <p>
 
91
<%
 
92
for (int i = 0; i < customers.size(); i++) {
 
93
  Customer c = (Customer)(customers).get(i);
 
94
  String cid = (String)c.getCustomerID();
 
95
%>
 
96
<a href="/customer/editCustomer.jsp?cid=<%=cid%>"> 
 
97
<%=c.getLastName()%>, <%=c.getFirstName()%></a> has
 
98
<%=c.getAddresses().size()%> addresses,
 
99
<%=c.getSubscriptions().size()%> subscriptions.
 
100
<p>
 
101
<%
 
102
}
 
103
%>
 
104
<%
 
105
    } catch(Exception e) {
 
106
        e.printStackTrace();
 
107
        out.println(e.toString());
 
108
    }
 
109
}
 
110
%>
 
111
 
 
112
<hr>
 
113
[<a href="/customer/index.html"><fmt:message key="home"/> </a>]
 
114
</center>
 
115
</body>
 
116
</html>