1 /**
2 * Copyright 2005-2014 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.rice.krad.web.form;
17
18 import java.io.Serializable;
19
20 /**
21 * Holds response data for a basic dialog that has been triggered from a server call.
22 *
23 * @author Kuali Rice Team (rice.collab@kuali.org)
24 */
25 public class DialogResponse implements Serializable {
26 private static final long serialVersionUID = -3533683391767027067L;
27
28 protected static final String TRUE_VALUES = "/true/yes/y/on/1/";
29
30 private String dialogId;
31
32 private String response;
33 private String explanation;
34
35 /**
36 * Default Constructor.
37 */
38 public DialogResponse() {
39 }
40
41 /**
42 * Constructor taking dialog id, response, and explanation.
43 */
44 public DialogResponse(String dialogId, String response, String explanation) {
45 this.dialogId = dialogId;
46 this.response = response;
47 this.explanation = explanation;
48 }
49
50 /**
51 * Id for the dialog whose response has been captured.
52 *
53 * @return dialog id
54 */
55 public String getDialogId() {
56 return dialogId;
57 }
58
59 /**
60 * @see DialogResponse#getDialogId()
61 */
62 public void setDialogId(String dialogId) {
63 this.dialogId = dialogId;
64 }
65
66 /**
67 * String response for the dialog action (button) that was chosen.
68 *
69 * @return String dialog response
70 */
71 public String getResponse() {
72 return response;
73 }
74
75 /**
76 * Returns the response for the dialog as a boolean.
77 *
78 * @return boolean dialog response
79 * @see DialogResponse#TRUE_VALUES
80 */
81 public boolean getResponseAsBoolean() {
82 if (response != null) {
83 StringBuilder builder = new StringBuilder();
84 builder.append("/").append(response.toLowerCase()).append("/");
85
86 if (TRUE_VALUES.contains(builder.toString())) {
87 return true;
88 }
89 }
90
91 return false;
92 }
93
94 /**
95 * @see DialogResponse#getResponse()
96 */
97 public void setResponse(String response) {
98 this.response = response;
99 }
100
101 /**
102 * If the dialog contained an explanation field that binds to the generic form property, the value (if any)
103 * given by the user.
104 *
105 * <p>Note if the explanation field was found to a different model property, its contents will not be
106 * available here. It should be retrieved from the corresponding model property.</p>
107 *
108 * @return string explanation value
109 */
110 public String getExplanation() {
111 return explanation;
112 }
113
114 /**
115 * @see DialogResponse#getExplanation()
116 */
117 public void setExplanation(String explanation) {
118 this.explanation = explanation;
119 }
120 }