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
19 import javax.servlet.http.HttpServletRequest;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.apache.log4j.Logger;
23 import org.kuali.rice.krad.inquiry.Inquirable;
24 import org.kuali.rice.krad.uif.UifConstants.ViewType;
25 import org.kuali.rice.krad.uif.view.InquiryView;
26 import org.kuali.rice.krad.web.bind.RequestAccessible;
27
28 /**
29 * Form class for <code>InquiryView</code> screens
30 *
31 * @author Kuali Rice Team (rice.collab@kuali.org)
32 */
33 public class InquiryForm extends UifFormBase {
34 private static final long serialVersionUID = 4733144086378429410L;
35
36 @RequestAccessible
37 private String dataObjectClassName;
38 private Object dataObject;
39
40 private boolean redirectedInquiry;
41
42 public InquiryForm() {
43 setViewTypeName(ViewType.INQUIRY);
44
45 redirectedInquiry = false;
46 }
47
48 /**
49 * Sets data object class on the form and/or inquirable.
50 */
51 @Override
52 public void postBind(HttpServletRequest request) {
53 super.postBind(request);
54
55 if (StringUtils.isBlank(getDataObjectClassName())) {
56 setDataObjectClassName(((InquiryView) getView()).getDataObjectClassName().getName());
57 }
58
59 Inquirable inquirable = getInquirable();
60
61 //KULRICE-12985 always update the data object class for inquirable, not just the first time.
62 if (inquirable != null) {
63 Class<?> dataObjectClass;
64 try {
65 dataObjectClass = Class.forName(getDataObjectClassName());
66 } catch (ClassNotFoundException e) {
67 throw new RuntimeException("Object class " + getDataObjectClassName() + " not found", e);
68 }
69
70 inquirable.setDataObjectClass(dataObjectClass);
71 }
72 }
73
74 /**
75 * Returns an {@link org.kuali.rice.krad.inquiry.Inquirable} instance associated with the inquiry view.
76 *
77 * @return Inquirable instance or null if one does not exist
78 */
79 public Inquirable getInquirable() {
80 if (getViewHelperService() != null) {
81 return (Inquirable) getViewHelperService();
82 }
83
84 return null;
85 }
86
87 /**
88 * Class name of the data object the inquiry will display
89 *
90 * <p>
91 * Used to set the data object class for the <code>Inquirable</code> which
92 * is then used to perform the inquiry query
93 * </p>
94 *
95 * @return String class name
96 */
97 public String getDataObjectClassName() {
98 return this.dataObjectClassName;
99 }
100
101 /**
102 * Setter for the inquiry data object class name
103 *
104 * @param dataObjectClassName
105 */
106 public void setDataObjectClassName(String dataObjectClassName) {
107 this.dataObjectClassName = dataObjectClassName;
108 }
109
110 /**
111 * Result data object for inquiry that will be display with the view
112 *
113 * @return Object object instance containing the inquiry data
114 */
115 public Object getDataObject() {
116 return this.dataObject;
117 }
118
119 /**
120 * Setter for the inquiry data object
121 *
122 * @param dataObject
123 */
124 public void setDataObject(Object dataObject) {
125 this.dataObject = dataObject;
126 }
127
128 /**
129 * Indicates whether the requested was redirected from the inquiry framework due to an external object
130 * request. This prevents the framework from performing another redirect check
131 *
132 * @return boolean true if request was a redirect, false if not
133 */
134 public boolean isRedirectedInquiry() {
135 return redirectedInquiry;
136 }
137
138 /**
139 * Setter for the redirected request indicator
140 *
141 * @param redirectedInquiry
142 */
143 public void setRedirectedInquiry(boolean redirectedInquiry) {
144 this.redirectedInquiry = redirectedInquiry;
145 }
146
147 }