1 /** 2 * Copyright 2005-2012 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.widget; 17 18 import org.apache.commons.lang.StringUtils; 19 import org.kuali.rice.krad.uif.view.View; 20 import org.kuali.rice.krad.uif.component.BindingInfo; 21 import org.kuali.rice.krad.uif.component.Component; 22 import org.kuali.rice.krad.uif.field.InputField; 23 import org.kuali.rice.krad.uif.field.AttributeQuery; 24 25 /** 26 * Widget that provides dynamic select options to the user as they 27 * are entering the value (also known as auto-complete) 28 * 29 * <p> 30 * Widget is backed by an <code>AttributeQuery</code> that provides 31 * the configuration for executing a query server side that will retrieve 32 * the valid option values. 33 * </p> 34 * 35 * @author Kuali Rice Team (rice.collab@kuali.org) 36 */ 37 public class Suggest extends WidgetBase { 38 private static final long serialVersionUID = 7373706855319347225L; 39 40 private AttributeQuery suggestQuery; 41 private String sourcePropertyName; 42 43 public Suggest() { 44 super(); 45 } 46 47 /** 48 * The following actions are performed: 49 * 50 * <ul> 51 * <li>Adjusts the query field mappings on the query based on the binding configuration of the field</li> 52 * <li>TODO: determine query if render is true and query is not set</li> 53 * </ul> 54 * 55 * @see org.kuali.rice.krad.uif.component.ComponentBase#performFinalize(org.kuali.rice.krad.uif.view.View, 56 * java.lang.Object, org.kuali.rice.krad.uif.component.Component) 57 */ 58 @Override 59 public void performFinalize(View view, Object model, Component parent) { 60 super.performFinalize(view, model, parent); 61 62 // if source property name set then can't render the Suggest widget 63 if (StringUtils.isBlank(sourcePropertyName)) { 64 setRender(false); 65 } 66 67 if (!isRender()) { 68 return; 69 } 70 71 InputField field = (InputField) parent; 72 BindingInfo bindingInfo = field.getBindingInfo(); 73 74 // adjust from side on query field mapping to match parent fields path 75 suggestQuery.updateQueryFieldMapping(bindingInfo); 76 } 77 78 /** 79 * Attribute query instance the will be executed to provide 80 * the suggest options 81 * 82 * @return AttributeQuery 83 */ 84 public AttributeQuery getSuggestQuery() { 85 return suggestQuery; 86 } 87 88 /** 89 * Setter for the suggest attribute query 90 * 91 * @param suggestQuery 92 */ 93 public void setSuggestQuery(AttributeQuery suggestQuery) { 94 this.suggestQuery = suggestQuery; 95 } 96 97 /** 98 * Name of the property on the query result object that provides 99 * the options for the suggest, values from this field will be 100 * collected and sent back on the result to provide as suggest options 101 * 102 * @return String source property name 103 */ 104 public String getSourcePropertyName() { 105 return sourcePropertyName; 106 } 107 108 /** 109 * Setter for the source property name 110 * 111 * @param sourcePropertyName 112 */ 113 public void setSourcePropertyName(String sourcePropertyName) { 114 this.sourcePropertyName = sourcePropertyName; 115 } 116 }