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.component;
21  
22  import org.apache.myfaces.tobago.component.InputSuggest;
23  import org.apache.myfaces.tobago.model.SuggestFilter;
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  
27  import javax.el.ValueExpression;
28  import javax.faces.component.UIComponentBase;
29  import javax.faces.component.behavior.ClientBehaviorHolder;
30  import javax.faces.context.FacesContext;
31  import java.lang.invoke.MethodHandles;
32  
33  /**
34   * {@link org.apache.myfaces.tobago.internal.taglib.component.SuggestTagDeclaration}
35   */
36  public abstract class AbstractUISuggest
37      extends UIComponentBase implements InputSuggest, ClientBehaviorHolder {
38  
39    private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
40  
41    /**
42     * @deprecated since 4.4.0.
43     */
44    @Deprecated
45    public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Suggest";
46    public static final String COMPONENT_FAMILY = "org.apache.myfaces.tobago.Suggest";
47  
48    private transient String query;
49  
50    @Override
51    public String getFamily() {
52      return COMPONENT_FAMILY;
53    }
54  
55    public abstract Integer getDelay();
56  
57    public abstract void setDelay(Integer delay);
58  
59    public abstract Integer getMinimumCharacters();
60  
61    public abstract void setMinimumCharacters(Integer minimumCharacters);
62  
63    public abstract void setFilter(SuggestFilter filter);
64  
65    public String getQuery() {
66      final ValueExpression expression = this.getValueExpression("query");
67      if (expression != null) {
68        try {
69          return (String) expression.getValue(FacesContext.getCurrentInstance().getELContext());
70        } catch (final Exception e) {
71          LOG.error("", e);
72          return null;
73        }
74      } else {
75        return query;
76      }
77    }
78  
79    public void setQuery(final String query) {
80      final ValueExpression expression = this.getValueExpression("query");
81      if (expression != null) {
82        try {
83          expression.setValue(FacesContext.getCurrentInstance().getELContext(), query);
84        } catch (final Exception e) {
85          LOG.error("query='" + query + "'", e);
86        }
87      } else {
88        this.query = query;
89      }
90    }
91  
92    public abstract boolean isUpdate();
93  
94    public abstract Integer getTotalCount();
95  
96    public abstract Integer getMaximumItems();
97  
98    public abstract boolean isLocalMenu();
99  }