001/** 002 * Copyright 2005-2016 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.widget; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.rice.krad.uif.view.View; 020import org.kuali.rice.krad.uif.component.BindingInfo; 021import org.kuali.rice.krad.uif.component.Component; 022import org.kuali.rice.krad.uif.field.InputField; 023import org.kuali.rice.krad.uif.field.AttributeQuery; 024 025/** 026 * Widget that provides dynamic select options to the user as they 027 * are entering the value (also known as auto-complete) 028 * 029 * <p> 030 * Widget is backed by an <code>AttributeQuery</code> that provides 031 * the configuration for executing a query server side that will retrieve 032 * the valid option values. 033 * </p> 034 * 035 * @author Kuali Rice Team (rice.collab@kuali.org) 036 */ 037public class Suggest extends WidgetBase { 038 private static final long serialVersionUID = 7373706855319347225L; 039 040 private AttributeQuery suggestQuery; 041 private String sourcePropertyName; 042 043 public Suggest() { 044 super(); 045 } 046 047 /** 048 * The following actions are performed: 049 * 050 * <ul> 051 * <li>Adjusts the query field mappings on the query based on the binding configuration of the field</li> 052 * <li>TODO: determine query if render is true and query is not set</li> 053 * </ul> 054 * 055 * @see org.kuali.rice.krad.uif.component.ComponentBase#performFinalize(org.kuali.rice.krad.uif.view.View, 056 * java.lang.Object, org.kuali.rice.krad.uif.component.Component) 057 */ 058 @Override 059 public void performFinalize(View view, Object model, Component parent) { 060 super.performFinalize(view, model, parent); 061 062 // if source property name set then can't render the Suggest widget 063 if (StringUtils.isBlank(sourcePropertyName)) { 064 setRender(false); 065 } 066 067 if (!isRender()) { 068 return; 069 } 070 071 InputField field = (InputField) parent; 072 BindingInfo bindingInfo = field.getBindingInfo(); 073 074 // adjust from side on query field mapping to match parent fields path 075 suggestQuery.updateQueryFieldMapping(bindingInfo); 076 } 077 078 /** 079 * Attribute query instance the will be executed to provide 080 * the suggest options 081 * 082 * @return AttributeQuery 083 */ 084 public AttributeQuery getSuggestQuery() { 085 return suggestQuery; 086 } 087 088 /** 089 * Setter for the suggest attribute query 090 * 091 * @param suggestQuery 092 */ 093 public void setSuggestQuery(AttributeQuery suggestQuery) { 094 this.suggestQuery = suggestQuery; 095 } 096 097 /** 098 * Name of the property on the query result object that provides 099 * 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}