KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > custom > tree > renderkit > html > HtmlTreeImageCommandLinkRenderer


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.custom.tree.renderkit.html;
17
18 import org.apache.myfaces.custom.tree.HtmlTreeImageCommandLink;
19 import org.apache.myfaces.custom.tree.HtmlTreeNode;
20 import org.apache.myfaces.renderkit.html.HTML;
21 import org.apache.myfaces.renderkit.html.HtmlLinkRendererBase;
22 import org.apache.myfaces.renderkit.html.HtmlRendererUtils;
23
24 import javax.faces.component.UIComponent;
25 import javax.faces.context.FacesContext;
26 import javax.faces.context.ResponseWriter;
27 import java.io.IOException JavaDoc;
28
29
30 /**
31  * @author <a HREF="mailto:oliver@rossmueller.com">Oliver Rossmueller</a>
32  * @version $Revision: 1.7 $ $Date: 2004/12/22 17:52:54 $
33  * $Log: HtmlTreeImageCommandLinkRenderer.java,v $
34  * Revision 1.7 2004/12/22 17:52:54 grantsmith
35  * Jira MYFACES-48: Tree Table Component Fixes & Tree Checkbox Support
36  *
37  * Revision 1.6 2004/10/13 11:50:58 matze
38  * renamed packages to org.apache
39  *
40  * Revision 1.5 2004/07/01 21:53:10 mwessendorf
41  * ASF switch
42  *
43  * Revision 1.4 2004/06/09 20:32:16 o_rossmueller
44  * fix: removed duplicate output of value
45  *
46  * Revision 1.3 2004/06/03 12:57:03 o_rossmueller
47  * modified link renderer to use one hidden field for all links according to 1.1 renderkit docs
48  * added onclick=clear_XXX to button
49  *
50  * Revision 1.2 2004/05/27 15:06:39 manolito
51  * bugfix: node labels not rendered any more
52  *
53  * Revision 1.1 2004/04/22 10:20:24 manolito
54  * tree component
55  *
56  */

57 public class HtmlTreeImageCommandLinkRenderer
58         extends HtmlLinkRendererBase
59 {
60
61     private static final Integer JavaDoc ZERO = new Integer JavaDoc(0);
62
63
64     public void decode(FacesContext facesContext, UIComponent component)
65     {
66         super.decode(facesContext, component);
67         String JavaDoc clientId = component.getClientId(facesContext);
68         String JavaDoc reqValue = (String JavaDoc)facesContext.getExternalContext().getRequestParameterMap().get(HtmlRendererUtils.getHiddenCommandLinkFieldName(HtmlRendererUtils.getFormName(component, facesContext)));
69         if (reqValue != null && reqValue.equals(clientId))
70         {
71             HtmlTreeNode node = (HtmlTreeNode)component.getParent();
72
73             node.toggleExpanded();
74         }
75     }
76
77
78     protected void renderCommandLinkStart(FacesContext facesContext,
79                                           UIComponent component,
80                                           String JavaDoc clientId,
81                                           Object JavaDoc value,
82                                           String JavaDoc style,
83                                           String JavaDoc styleClass) throws IOException JavaDoc
84     {
85
86         super.renderCommandLinkStart(facesContext, component, clientId, value, style, styleClass);
87
88         String JavaDoc url = ((HtmlTreeImageCommandLink)component).getImage();
89
90         if ((url != null) && (url.length() > 0))
91         {
92             ResponseWriter writer = facesContext.getResponseWriter();
93             writer.startElement(HTML.IMG_ELEM, component);
94             String JavaDoc src = facesContext.getApplication().getViewHandler().getResourceURL(facesContext, url);
95             //String src;
96
//if (url.startsWith(HTML.HREF_PATH_SEPARATOR))
97
//{
98
// String path = facesContext.getExternalContext().getRequestContextPath();
99
// src = path + url;
100
//}
101
//else
102
//{
103
// src = url;
104
//}
105
//Encode URL
106
//Although this is an url url, encodeURL is no nonsense, because the
107
//actual url url could also be a dynamic servlet request:
108
//src = facesContext.getExternalContext().encodeResourceURL(src);
109
writer.writeAttribute(HTML.SRC_ATTR, src, null);
110             writer.writeAttribute(HTML.BORDER_ATTR, ZERO, null);
111
112             HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.IMG_PASSTHROUGH_ATTRIBUTES);
113
114             writer.endElement(HTML.IMG_ELEM);
115         }
116     }
117 }
118
Popular Tags