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 package org.apache.myfaces.custom.suggestajax;
20
21 import java.io.IOException;
22
23 import javax.faces.context.FacesContext;
24 import javax.faces.el.MethodBinding;
25 import javax.faces.render.Renderer;
26
27 import org.apache.myfaces.component.LocationAware;
28 import org.apache.myfaces.component.html.ext.HtmlInputText;
29 import org.apache.myfaces.custom.ajax.api.AjaxComponent;
30 import org.apache.myfaces.custom.ajax.api.AjaxRenderer;
31
32 /**
33 *
34 * @JSFComponent
35 * configExcluded = "true"
36 * class = "org.apache.myfaces.custom.suggestajax.SuggestAjax"
37 * tagClass = "org.apache.myfaces.custom.suggestajax.SuggestAjaxTag"
38 * tagSuperclass = "org.apache.myfaces.custom.suggestajax.AbstractSuggestAjaxTag"
39 * @author Gerald Muellan
40 * Date: 25.03.2006
41 * Time: 17:06:04
42 */
43 public abstract class AbstractSuggestAjax extends HtmlInputText
44 implements AjaxComponent, LocationAware
45 {
46 public static final String COMPONENT_TYPE = "org.apache.myfaces.SuggestAjax";
47 public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.SuggestAjax";
48
49 private MethodBinding _suggestedItemsMethod;
50
51 public Object saveState(FacesContext context)
52 {
53 Object[] values = new Object[4];
54 values[0] = super.saveState(context);
55 values[1] = saveAttachedState(context, _suggestedItemsMethod);
56
57 return values;
58 }
59
60 public void restoreState(FacesContext context, Object state)
61 {
62 Object values[] = (Object[])state;
63 super.restoreState(context, values[0]);
64 _suggestedItemsMethod = (MethodBinding) restoreAttachedState(context, values[1]);
65 }
66
67 public void encodeAjax(FacesContext context)
68 throws IOException
69 {
70 if (context == null) throw new NullPointerException("context");
71 if (!isRendered()) return;
72 Renderer renderer = getRenderer(context);
73 if (renderer != null && renderer instanceof AjaxRenderer)
74 {
75 ((AjaxRenderer) renderer).encodeAjax(context, this);
76 }
77 }
78
79 public void decodeAjax(FacesContext context)
80 {
81
82 }
83
84 public void encodeChildren(FacesContext context) throws IOException
85 {
86 super.encodeChildren(context);
87 }
88
89 public void setSuggestedItemsMethod(MethodBinding suggestedItemsMethod)
90 {
91 _suggestedItemsMethod = suggestedItemsMethod;
92 }
93
94 /**
95 * Reference to the method which returns the suggested items
96 *
97 * @JSFProperty
98 * inheritedTag = "true"
99 * @return
100 */
101 public MethodBinding getSuggestedItemsMethod()
102 {
103 return _suggestedItemsMethod;
104 }
105
106 /**
107 * optional attribute to identify the max size of suggested Values.
108 * If specified in tableSuggestAjax, paginator functionality is used.
109 *
110 * @JSFProperty
111 * inheritedTag = "true"
112 * @return
113 */
114 public abstract Integer getMaxSuggestedItems();
115
116
117 /**
118 * Force the charset of the Response
119 *
120 * @JSFProperty
121 * literalOnly = "true"
122 * @return
123 */
124 public abstract String getCharset();
125
126 /**
127 * An alternate location to find javascript resources.
128 * If no values is specified, javascript will be loaded
129 * from the resources directory using AddResource and
130 * ExtensionsFilter.
131 *
132 * @JSFProperty
133 */
134 public abstract String getJavascriptLocation();
135
136 /**
137 * An alternate location to find image resources. If no
138 * values is specified, images will be loaded from the
139 * resources directory using AddResource and ExtensionsFilter.
140 *
141 * @JSFProperty
142 */
143 public abstract String getImageLocation();
144
145 /**
146 * An alternate location to find stylesheet resources. If no
147 * values is specified, stylesheets will be loaded from the
148 * resources directory using AddResource and ExtensionsFilter.
149 *
150 * @JSFProperty
151 */
152 public abstract String getStyleLocation();
153
154
155 }