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.InputSuggest2;
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  
32  public abstract class AbstractUISuggest
33      extends UIComponentBase implements InputSuggest2, ClientBehaviorHolder {
34  
35    private static final Logger LOG = LoggerFactory.getLogger(AbstractUISuggest.class);
36  
37    public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Suggest";
38    public static final String COMPONENT_FAMILY = "org.apache.myfaces.tobago.Suggest";
39  
40    private transient String query;
41  
42    @Override
43    public String getFamily() {
44      return COMPONENT_FAMILY;
45    }
46  
47    public abstract Integer getDelay();
48  
49    public abstract void setDelay(Integer delay);
50  
51    public abstract Integer getMinimumCharacters();
52  
53    public abstract void setMinimumCharacters(Integer minimumCharacters);
54  
55    public abstract void setFilter(SuggestFilter filter);
56  
57    public String getQuery() {
58      final ValueExpression expression = this.getValueExpression("query");
59      if (expression != null) {
60        try {
61          return (String) expression.getValue(FacesContext.getCurrentInstance().getELContext());
62        } catch (Exception e) {
63          LOG.error("", e);
64          return null;
65        }
66      } else {
67        return query;
68      }
69    }
70  
71    public void setQuery(String query) {
72      final ValueExpression expression = this.getValueExpression("query");
73      if (expression != null) {
74        try {
75          expression.setValue(FacesContext.getCurrentInstance().getELContext(), query);
76        } catch (Exception e) {
77          LOG.error("query='" + query + "'", e);
78        }
79      } else {
80        this.query = query;
81      }
82    }
83  
84    public abstract boolean isUpdate();
85  
86    public abstract Integer getTotalCount();
87  
88    public abstract Integer getMaximumItems();
89  }