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