View Javadoc

1   // ---------- Attention: Generated code, please do not modify! -----------  
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.myfaces.tobago.component;
21  
22  import javax.el.MethodExpression;
23  import javax.faces.context.FacesContext;
24  import org.apache.myfaces.tobago.context.Markup;
25  import org.apache.myfaces.tobago.internal.component.AbstractUISuggest;
26  import org.apache.myfaces.tobago.model.SuggestFilter;
27  import org.apache.myfaces.tobago.internal.util.ArrayUtils;
28  import org.apache.myfaces.tobago.internal.util.StringUtils;
29  import org.apache.myfaces.tobago.internal.util.Deprecation;
30  import org.apache.myfaces.tobago.renderkit.MarginValues;
31  import org.apache.myfaces.tobago.renderkit.SpacingValues;
32  import org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer;
33  import javax.el.ELException;
34  import javax.faces.FacesException;
35  import java.util.ArrayList;
36  import java.util.List;
37  import javax.el.MethodExpression;
38  import javax.el.ValueExpression;
39  
40  /** 
41   Renders a list of suggested texts for a given input field.
42  
43    Basic features:
44    <ul>
45      <li>provide a list directly while rendering (not AJAX needed) [todo]</li>
46      <li>update by typing (AJAX)</li>
47      <li>minimum number of typed characters (to avoid useless requests)</li>
48      <li>update delay (useful for optimization)</li>
49      <li>filter on client side (useful for optimization) [todo]</li>
50    </ul>
51    * UIComponent class, generated from template {@code component2.0.stg} with class
52    * {@link org.apache.myfaces.tobago.internal.taglib.component.SuggestTagDeclaration}.
53   */
54  public class UISuggest
55      extends AbstractUISuggest implements SupportsMarkup {
56  
57    public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Suggest";
58  
59    public static final String COMPONENT_FAMILY = "javax.faces.Input";
60  
61    private org.apache.myfaces.tobago.context.Markup currentMarkup;
62  
63    enum PropertyKeys {
64      update,
65      maximumItems,
66      suggestMethod,
67      markup,
68      totalCount,
69      minimumCharacters,
70      delay,
71      filter,
72    }
73  
74    public String getFamily() {
75      return COMPONENT_FAMILY;
76    }
77  
78  
79    /**
80    TODO: not implemented yet
81     <p/>
82     Should the list be updated while typing (via AJAX). This is the default behaviour.
83     If you set this value to <code>false</code>, please set the <code>minimumCharacters="0"</pre>.
84    <br />Default: <code>true</code>
85    */
86    public boolean isUpdate() {
87      Boolean bool = (Boolean) getStateHelper().eval(PropertyKeys.update);
88      if (bool != null) {
89        return bool;
90      }
91      return true;
92    }
93  
94    public void setUpdate(boolean update) {
95      getStateHelper().put(PropertyKeys.update, update);
96    }
97  
98    /**
99    The maximum number of item to display in the drop down list.
100   <br />Default: <code>10</code>
101   */
102   public java.lang.Integer getMaximumItems() {
103     Number value  = (Number) getStateHelper().eval(PropertyKeys.maximumItems);
104     if (value != null) {
105       return value.intValue();
106     }
107     return 10;
108   }
109 
110   public void setMaximumItems(java.lang.Integer maximumItems) {
111     getStateHelper().put(PropertyKeys.maximumItems, maximumItems);
112   }
113 
114   /**
115    * @deprecated since 2.0.0
116    */
117   @Deprecated
118   public javax.faces.el.MethodBinding getSuggestMethod() {
119     javax.el.MethodExpression expression = getSuggestMethodExpression();
120     if (expression instanceof MethodBindingToMethodExpression) {
121       return ((MethodBindingToMethodExpression)expression).getMethodBinding();
122     }
123     if (expression != null) {
124        return new MethodExpressionToMethodBinding(expression);
125     }
126     return null;
127   }
128 
129   /**
130    * @deprecated since 2.0.0
131    */
132   @Deprecated
133   public void setSuggestMethod(javax.faces.el.MethodBinding suggestMethod) {
134     if (suggestMethod != null) {
135       setSuggestMethodExpression(new MethodBindingToMethodExpression(suggestMethod));
136     } else {
137       setSuggestMethodExpression(null);
138     }
139   }
140 
141   public javax.el.MethodExpression getSuggestMethodExpression() {
142     return (javax.el.MethodExpression) getStateHelper().eval(PropertyKeys.suggestMethod);
143   }
144 
145   public void setSuggestMethodExpression(javax.el.MethodExpression suggestMethod) {
146     getStateHelper().put(PropertyKeys.suggestMethod, suggestMethod);
147   }
148 
149 
150   public org.apache.myfaces.tobago.context.Markup getMarkup() {
151     Object object = getStateHelper().eval(PropertyKeys.markup);
152     if (object != null) {
153       return Markup.valueOf(object);
154     }
155     return null;
156   }
157 
158   public void setMarkup(org.apache.myfaces.tobago.context.Markup markup) {
159     getStateHelper().put(PropertyKeys.markup, markup);
160   }
161 
162   /**
163   The real size of the result list.
164    Typically the result list will be cropped (in the backend) to save memory.
165    This value can be set, to show the user there are more results for the given string.
166    If the value is -1, no hint will be displayed.
167   <br />Default: <code>-1</code>
168   */
169   public java.lang.Integer getTotalCount() {
170     Number value  = (Number) getStateHelper().eval(PropertyKeys.totalCount);
171     if (value != null) {
172       return value.intValue();
173     }
174     return -1;
175   }
176 
177   public void setTotalCount(java.lang.Integer totalCount) {
178     getStateHelper().put(PropertyKeys.totalCount, totalCount);
179   }
180 
181   public org.apache.myfaces.tobago.context.Markup getCurrentMarkup() {
182     if (currentMarkup != null) {
183       return currentMarkup;
184     }
185     return null;
186   }
187 
188   public void setCurrentMarkup(org.apache.myfaces.tobago.context.Markup currentMarkup) {
189     this.currentMarkup = currentMarkup;
190   }
191 
192   /**
193   Minimum number of characters to type before the list will be requested.
194    If the value is 0, there will be send an initial list to the client.
195    So, if you set <pre>update="false"</pre> this value should be 0.
196   <br />Default: <code>1</code>
197   */
198   public java.lang.Integer getMinimumCharacters() {
199     Number value  = (Number) getStateHelper().eval(PropertyKeys.minimumCharacters);
200     if (value != null) {
201       return value.intValue();
202     }
203     return 1;
204   }
205 
206   public void setMinimumCharacters(java.lang.Integer minimumCharacters) {
207     getStateHelper().put(PropertyKeys.minimumCharacters, minimumCharacters);
208   }
209 
210   /**
211   Time in milli seconds before the list will be requested (by AJAX).
212   <br />Default: <code>300</code>
213   */
214   public java.lang.Integer getDelay() {
215     Number value  = (Number) getStateHelper().eval(PropertyKeys.delay);
216     if (value != null) {
217       return value.intValue();
218     }
219     return 300;
220   }
221 
222   public void setDelay(java.lang.Integer delay) {
223     getStateHelper().put(PropertyKeys.delay, delay);
224   }
225 
226   /**
227   TODO: not implemented yet
228    <p/>
229    Additional client side filtering of the result list.
230    This is useful when sending the full list initially to the client and
231    setting <code>update=false</code>.
232    <p/>
233    Possible values are:
234    <dl>
235      <dt>all</dt>
236      <dd>no filtering</dd>
237      <dt>prefix</dt>
238      <dd>checks if the suggested string starts with the typed text</dd>
239      <dt>contains</dt>
240      <dd>checks if the typed text is inside of the suggested string</dd>
241    </dl>
242    <p/>
243    The filter will only applied on the client side and
244    only if server updated (by AJAX) are turned off (<code>update=false</code>);
245   <br />Default: <code>SuggestFilter.ALL</code><br />Allowed Values: <code>all,prefix,contains</code>
246   */
247   public org.apache.myfaces.tobago.model.SuggestFilter getFilter() {
248     org.apache.myfaces.tobago.model.SuggestFilter filter = (org.apache.myfaces.tobago.model.SuggestFilter) getStateHelper().eval(PropertyKeys.filter);
249     if (filter != null) {
250       return filter;
251     }
252     return SuggestFilter.ALL;
253   }
254 
255   public void setFilter(org.apache.myfaces.tobago.model.SuggestFilter filter) {
256     getStateHelper().put(PropertyKeys.filter, filter);
257   }
258 
259   public Object saveState(FacesContext context) {
260     currentMarkup = null;
261     return super.saveState(context);
262   }
263 
264 }