2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to you under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   *
17   * $Id: Popup.java 499272 2007-01-24 06:10:08Z craigmcc $
18   */
19  
20  package org.apache.shale.examples.test.dialog.basic;
21  
22  import javax.faces.context.FacesContext;
23  import javax.faces.el.ValueBinding;
24  
25  import org.apache.shale.dialog.Constants;
26  import org.apache.shale.dialog.DialogContext;
27  import org.apache.shale.dialog.DialogHelper;
28  
29  /***
30   * <p>Event handlers for the "PopUp" dialog.</p>
31   */
32  public class Popup {
33      
34  
35      /***
36       * <p>Cancel the popup dialog.</p>
37       */
38      public String cancel() {
39  
40          // Do not copy anything back to our parent dialog's data
41          return "cancelled";
42  
43      }
44  
45  
46      /***
47       * <p>Refresh the list of cities for the currently selected state.</p>
48       */
49      public String refresh() {
50  
51          // The act of updating our selected state is all we need to do
52          return null;
53  
54      }
55  
56  
57      /***
58       * <p>Set up the data for this dialog.</p>
59       */
60      public String setup() {
61  
62          // Import the currently selected state from our parent dialog
63          FacesContext context = FacesContext.getCurrentInstance();
64          ValueBinding vb = context.getApplication().createValueBinding("#{dialog.parent.data.state}");
65          String state = (String) vb.getValue(context);
66  
67          // Set the currently selected state into our dialog data
68          DialogContext dcontext = DialogHelper.getDialogContext(context);
69          PopupData data = (PopupData) dcontext.getData();
70          data.setState(state);
71  
72          // Proceed to the first page of the popup
73          return "success";
74  
75      }
76  
77  
78      /***
79       * <p>Select the row corresponding to this button.</p>
80       */
81      public String select() {
82  
83          // Identify the selected row from the table
84          FacesContext context = FacesContext.getCurrentInstance();
85          City city = (City)
86            context.getApplication().getVariableResolver().
87            resolveVariable(context, "city");
88  
89          // Copy relevant values back to our parent dialog's data
90          ValueBinding vb = null;
91          vb = context.getApplication().createValueBinding("#{dialog.parent.data.city}");
92          vb.setValue(context, city.getCity());
93          vb = context.getApplication().createValueBinding("#{dialog.parent.data.state}");
94          vb.setValue(context, city.getState());
95          vb = context.getApplication().createValueBinding("#{dialog.parent.data.zipCode}");
96          vb.setValue(context, city.getZipCode());
97  
98          // Exit the dialog now that we have copied back the relevant values
99          return "finished";
100 
101     }
102 
103 
104 }