1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.custom.suggestajax.tablesuggestajax;
20
21 import javax.faces.application.Application;
22 import javax.faces.el.ValueBinding;
23 import javax.faces.webapp.UIComponentTag;
24
25 import org.apache.myfaces.custom.suggestajax.AbstractSuggestAjaxTag;
26 import org.apache.myfaces.custom.suggestajax.SuggestAjax;
27
28 import com.sun.facelets.FaceletContext;
29 import com.sun.facelets.tag.TagAttribute;
30 import com.sun.facelets.tag.jsf.ComponentConfig;
31 import com.sun.facelets.tag.jsf.html.HtmlComponentHandler;
32
33 public class TableSuggestAjaxTagHandler extends HtmlComponentHandler
34 {
35 private static final String SUGGESTED_ITEMS_METHOD = "suggestedItemsMethod";
36 private static final String MAX_SUGGESTED_ITEMS = "maxSuggestedItems";
37
38 private TagAttribute suggestedItemsMethodAttr;
39 private TagAttribute maxSuggestedItemsAttr;
40
41 public TableSuggestAjaxTagHandler(ComponentConfig config)
42 {
43 super(config);
44 suggestedItemsMethodAttr = getAttribute(SUGGESTED_ITEMS_METHOD);
45 maxSuggestedItemsAttr = getAttribute(MAX_SUGGESTED_ITEMS);
46 }
47
48 protected void setAttributes(FaceletContext ctx, Object instance)
49 {
50 super.setAttributes(ctx, instance);
51
52 Application app = ctx.getFacesContext().getApplication();
53
54 SuggestAjax comp = (SuggestAjax) instance;
55
56 if (maxSuggestedItemsAttr != null){
57 String maxSuggestedItems = maxSuggestedItemsAttr.getValue();
58
59 if (maxSuggestedItems != null)
60 {
61 if (UIComponentTag.isValueReference(maxSuggestedItems))
62 {
63 ValueBinding vb = app.createValueBinding(maxSuggestedItems);
64 comp.setValueBinding(MAX_SUGGESTED_ITEMS, vb);
65 }
66 else
67 {
68 comp.getAttributes().put(MAX_SUGGESTED_ITEMS, Integer.valueOf(maxSuggestedItems));
69 }
70 }
71 }
72
73 if (suggestedItemsMethodAttr != null){
74 String suggestedItemsMethod = suggestedItemsMethodAttr.getValue();
75 if (suggestedItemsMethod != null)
76 {
77 AbstractSuggestAjaxTag.setSuggestedItemsMethodProperty(ctx.getFacesContext(),
78 comp,suggestedItemsMethod);
79 }
80 }
81 }
82
83 }