001/** 002 * Copyright 2005-2018 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.uif.view; 017 018import java.util.HashMap; 019import java.util.Map; 020 021import org.apache.commons.lang.StringUtils; 022import org.kuali.rice.krad.datadictionary.parse.BeanTag; 023import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute; 024import org.kuali.rice.krad.datadictionary.parse.BeanTags; 025import org.kuali.rice.krad.uif.container.PageGroup; 026import org.kuali.rice.krad.uif.util.LifecycleElement; 027import org.kuali.rice.krad.web.form.UifFormBase; 028 029/** 030 * Provides configuration for {@link View} instances that render an HTML form. 031 * 032 * @author Kuali Rice Team (rice.collab@kuali.org) 033 */ 034@BeanTag(name = "view", parent = "Uif-FormView") 035public class FormView extends View { 036 private static final long serialVersionUID = -3291164284675273147L; 037 038 private boolean renderForm; 039 private boolean validateServerSide; 040 private boolean validateClientSide; 041 042 private String formPostUrl; 043 044 private Map<String, String> additionalHiddenValues; 045 046 public FormView() { 047 renderForm = true; 048 validateServerSide = true; 049 validateClientSide = true; 050 applyDirtyCheck = true; 051 052 additionalHiddenValues = new HashMap<String, String>(); 053 } 054 055 /** 056 * The following is performed: 057 * 058 * <ul> 059 * <li>Adds to its document ready script the setupValidator js function for setting 060 * up the validator for this view</li> 061 * </ul> 062 * 063 * {@inheritDoc} 064 */ 065 @Override 066 public void performFinalize(Object model, LifecycleElement parent) { 067 super.performFinalize(model, parent); 068 069 UifFormBase form = (UifFormBase) model; 070 071 PageGroup page = getCurrentPage(); 072 073 if ((page != null) && StringUtils.isNotBlank(page.getFormPostUrl())) { 074 form.setFormPostUrl(page.getFormPostUrl()); 075 } 076 else if (StringUtils.isNotBlank(formPostUrl)) { 077 form.setFormPostUrl(formPostUrl); 078 } 079 } 080 081 /** 082 * Indicates whether a Form element should be rendered for the View. This is 083 * necessary for pages that need to submit data back to the server. Note 084 * that even if a page is read-only, a form element is generally needed for 085 * the navigation. Defaults to true 086 * 087 * @return true if the form element should be rendered, false if it should 088 * not be 089 */ 090 @BeanTagAttribute 091 public boolean isRenderForm() { 092 return this.renderForm; 093 } 094 095 /** 096 * Setter for the render form indicator 097 * 098 * @param renderForm 099 */ 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}