View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.internal.taglib.component;
21  
22  import org.apache.myfaces.tobago.apt.annotation.DynamicExpression;
23  import org.apache.myfaces.tobago.apt.annotation.Tag;
24  import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
25  import org.apache.myfaces.tobago.apt.annotation.UIComponentTag;
26  import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
27  import org.apache.myfaces.tobago.component.RendererTypes;
28  import org.apache.myfaces.tobago.internal.taglib.declaration.HasIdBindingAndRendered;
29  import org.apache.myfaces.tobago.model.SuggestFilter;
30  
31  import javax.faces.component.UIInput;
32  
33  /**
34   * Renders a list of suggested texts for a given input field.
35   *
36   * Basic features:
37   * <ul>
38   *   <li>provide a list directly while rendering (not AJAX needed) [todo]</li>
39   *   <li>update by typing (AJAX)</li>
40   *   <li>minimum number of typed characters (to avoid useless requests)</li>
41   *   <li>update delay (useful for optimization)</li>
42   *   <li>filter on client side (useful for optimization) [todo]</li>
43   * </ul>
44   *
45   * @since 2.0.0
46   */
47  @Tag(name = "suggest")
48  @UIComponentTag(
49      uiComponent = "org.apache.myfaces.tobago.component.UISuggest",
50      uiComponentBaseClass = "org.apache.myfaces.tobago.internal.component.AbstractUISuggest",
51      componentFamily = UIInput.COMPONENT_FAMILY,
52      rendererType = RendererTypes.SUGGEST,
53      allowedChildComponenents = {
54          "org.apache.myfaces.tobago.SelectItems",
55          "org.apache.myfaces.tobago.SelectItem"
56      }/* todo ,
57      behaviors = {
58          @Behavior(
59              name = ClientBehaviors.SUGGEST,
60              isDefault = true)
61      }*/)
62  public interface SuggestTagDeclaration extends HasIdBindingAndRendered {
63  
64    /**
65     * MethodBinding which generates a list of suggested input values based on
66     * the currently entered text, which could be retrieved via getSubmittedValue() on the UIIn.
67     * The expression has to evaluate to a public method which has a javax.faces.component.UIInput parameter
68     * and returns a List&lt;String&gt;, a List&lt;org.apache.myfaces.tobago.model.AutoSuggestItem&gt;
69     * or a org.apache.myfaces.tobago.model.AutoSuggestItems.
70     *
71     * @deprecated Please use an <code>&lt;tc:selectItems&gt;</code> tag or a list of <code>&lt;tc:selectItem&gt;</code>
72     * tags (TODO: not implemented yet).
73     */
74    @Deprecated
75    @TagAttribute
76    @UIComponentTagAttribute(type = {},
77        expression = DynamicExpression.METHOD_EXPRESSION_REQUIRED,
78        methodSignature = "javax.faces.component.UIInput",
79        methodReturnType = "java.lang.Object")
80    void setSuggestMethod(String suggestMethod);
81  
82    /**
83     * Minimum number of characters to type before the list will be requested.
84     * If the value is 0, there will be send an initial list to the client.
85     * So, if you set <pre>update="false"</pre> this value should be 0.
86     */
87    @TagAttribute
88    @UIComponentTagAttribute(type = "java.lang.Integer", defaultValue = "1")
89    void setMinimumCharacters(String minimumCharacters);
90  
91    /**
92     * Time in milli seconds before the list will be requested (by AJAX).
93     */
94    @TagAttribute
95    @UIComponentTagAttribute(type = "java.lang.Integer", defaultValue = "200")
96    void setDelay(String delay);
97  
98    /**
99     * The maximum number of item to display in the drop down list.
100    */
101   @TagAttribute
102   @UIComponentTagAttribute(type = "java.lang.Integer", defaultValue = "10")
103   void setMaximumItems(String maximumItems);
104 
105   /**
106    * The real size of the result list.
107    * Typically the result list will be cropped (in the backend) to save memory.
108    * This value can be set, to show the user there are more results for the given string.
109    * If the value is -1, no hint will be displayed.
110    */
111   @TagAttribute
112   @UIComponentTagAttribute(type = "java.lang.Integer", defaultValue = "-1")
113   void setTotalCount(String totalCount);
114 
115   /**
116    * TODO: not implemented yet
117    * <p>
118    * Additional client side filtering of the result list.
119    * This is useful when sending the full list initially to the client and
120    * setting <code>update=false</code>.
121    * </p>
122    * <p>
123    * Possible values are:
124    * </p>
125    * <dl>
126    *   <dt>all</dt>
127    *   <dd>no filtering</dd>
128    *   <dt>prefix</dt>
129    *   <dd>checks if the suggested string starts with the typed text</dd>
130    *   <dt>contains</dt>
131    *   <dd>checks if the typed text is inside of the suggested string</dd>
132    * </dl>
133    * <p>
134    * The filter will only applied on the client side and
135    * only if server updated (by AJAX) are turned off (<code>update=false</code>);
136    * </p>
137    */
138   @TagAttribute
139   @UIComponentTagAttribute(
140       type = "org.apache.myfaces.tobago.model.SuggestFilter",
141       defaultValue = "SuggestFilter.ALL",
142       allowedValues = {
143           SuggestFilter.STRING_ALL,
144           SuggestFilter.STRING_PREFIX,
145           SuggestFilter.STRING_CONTAINS})
146   void setFilter(String filter);
147 
148   /**
149    * TODO: not implemented yet
150    * <p>
151    * Should the list be updated while typing (via AJAX). This is the default behaviour.
152    * If you set this value to <code>false</code>, please set the <code>minimumCharacters="0"</code>.
153    * </p>
154    */
155   @TagAttribute
156   @UIComponentTagAttribute(type = "boolean", defaultValue = "true")
157   void setUpdate(String update);
158 
159   /**
160    * The query is the string typed by the user.
161    */
162   @TagAttribute
163   @UIComponentTagAttribute(generate = false, isTransient = true)
164   void setQuery(String query);
165 }