1 /**
2 * Copyright 2005-2015 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.uif.view;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
23 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
24 import org.kuali.rice.krad.datadictionary.parse.BeanTags;
25 import org.kuali.rice.krad.uif.container.PageGroup;
26 import org.kuali.rice.krad.uif.util.LifecycleElement;
27 import org.kuali.rice.krad.web.form.UifFormBase;
28
29 /**
30 * Provides configuration for {@link View} instances that render an HTML form.
31 *
32 * @author Kuali Rice Team (rice.collab@kuali.org)
33 */
34 @BeanTag(name = "view", parent = "Uif-FormView")
35 public class FormView extends View {
36 private static final long serialVersionUID = -3291164284675273147L;
37
38 private boolean renderForm;
39 private boolean validateServerSide;
40 private boolean validateClientSide;
41
42 private String formPostUrl;
43
44 private Map<String, String> additionalHiddenValues;
45
46 public FormView() {
47 renderForm = true;
48 validateServerSide = true;
49 validateClientSide = true;
50 applyDirtyCheck = true;
51
52 additionalHiddenValues = new HashMap<String, String>();
53 }
54
55 /**
56 * The following is performed:
57 *
58 * <ul>
59 * <li>Adds to its document ready script the setupValidator js function for setting
60 * up the validator for this view</li>
61 * </ul>
62 *
63 * {@inheritDoc}
64 */
65 @Override
66 public void performFinalize(Object model, LifecycleElement parent) {
67 super.performFinalize(model, parent);
68
69 UifFormBase form = (UifFormBase) model;
70
71 PageGroup page = getCurrentPage();
72
73 if ((page != null) && StringUtils.isNotBlank(page.getFormPostUrl())) {
74 form.setFormPostUrl(page.getFormPostUrl());
75 }
76 else if (StringUtils.isNotBlank(formPostUrl)) {
77 form.setFormPostUrl(formPostUrl);
78 }
79 }
80
81 /**
82 * Indicates whether a Form element should be rendered for the View. This is
83 * necessary for pages that need to submit data back to the server. Note
84 * that even if a page is read-only, a form element is generally needed for
85 * the navigation. Defaults to true
86 *
87 * @return true if the form element should be rendered, false if it should
88 * not be
89 */
90 @BeanTagAttribute
91 public boolean isRenderForm() {
92 return this.renderForm;
93 }
94
95 /**
96 * Setter for the render form indicator
97 *
98 * @param renderForm
99 */
100 public void setRenderForm(boolean renderForm) {
101 this.renderForm = renderForm;
102 }
103
104 /**
105 * Indicates whether to perform the validate model phase of the view
106 * lifecycle. This phase will validate the model against configured
107 * dictionary validations and report errors. Defaults to true
108 *
109 * @return boolean true if model data should be validated, false if it
110 * should not be
111 */
112 @BeanTagAttribute
113 public boolean isValidateServerSide() {
114 return this.validateServerSide;
115 }
116
117 /**
118 * Setter for the validate server side indicator
119 *
120 * @param validateServerSide
121 */
122 public void setValidateServerSide(boolean validateServerSide) {
123 this.validateServerSide = validateServerSide;
124 }
125
126 /**
127 * Indicates whether to perform on-the-fly validation on the client using js
128 * during user data entry. Defaults to true
129 *
130 * @return the validateClientSide
131 */
132 @BeanTagAttribute
133 public boolean isValidateClientSide() {
134 return validateClientSide;
135 }
136
137 /**
138 * Setter for the validate client side indicator
139 *
140 * @param validateClientSide
141 */
142 public void setValidateClientSide(boolean validateClientSide) {
143 this.validateClientSide = validateClientSide;
144 }
145
146 /**
147 * Specifies the URL the view's form should post to
148 *
149 * <p>
150 * Any valid form post URL (full or relative) can be specified. If left
151 * empty, the form will be posted to the same URL of the preceding request
152 * URL.
153 * </p>
154 *
155 * @return post URL
156 */
157 @BeanTagAttribute
158 public String getFormPostUrl() {
159 return this.formPostUrl;
160 }
161
162 /**
163 * Setter for the form post URL
164 *
165 * @param formPostUrl
166 */
167 public void setFormPostUrl(String formPostUrl) {
168 this.formPostUrl = formPostUrl;
169 }
170
171 /**
172 * Map of property path and values that will get written out as hidden elements.
173 *
174 * @return map for additional hiddens, key will be used as the name of the elememt, the map value will
175 * be the value of the element
176 */
177 @BeanTagAttribute
178 public Map<String, String> getAdditionalHiddenValues() {
179 return additionalHiddenValues;
180 }
181
182 /**
183 * @see FormView#getAdditionalHiddenValues()
184 */
185 public void setAdditionalHiddenValues(Map<String, String> additionalHiddenValues) {
186 this.additionalHiddenValues = additionalHiddenValues;
187 }
188 }