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