1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.renderkit.html.ext;
20
21 import java.io.IOException;
22
23 import javax.faces.component.UIComponent;
24 import javax.faces.component.UIOutput;
25 import javax.faces.context.FacesContext;
26 import javax.faces.context.ResponseWriter;
27
28 import org.apache.myfaces.component.UserRoleUtils;
29 import org.apache.myfaces.component.html.ext.HtmlCommandLink;
30 import org.apache.myfaces.renderkit.html.jsf.ExtendedHtmlLinkRenderer;
31 import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
32 import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
33 import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
34
35
36
37
38
39
40
41
42
43
44 public class HtmlLinkRenderer
45 extends ExtendedHtmlLinkRenderer
46 {
47
48
49 protected void renderCommandLinkStart(FacesContext facesContext,
50 UIComponent component,
51 String clientId,
52 Object value,
53 String style,
54 String styleClass) throws IOException
55 {
56
57 if (UserRoleUtils.isEnabledOnUserRole(component) &&
58 !((HtmlCommandLink) component).isDisabled() )
59 {
60 super.renderCommandLinkStart(facesContext, component, clientId, value, style, styleClass);
61 }
62 else
63 {
64
65
66
67
68 if(((HtmlCommandLink) component).getDisabledStyle() != null)
69 {
70 style = ((HtmlCommandLink) component).getDisabledStyle();
71 }
72
73 if(((HtmlCommandLink) component).getDisabledStyleClass() != null)
74 {
75 styleClass = ((HtmlCommandLink) component).getDisabledStyleClass();
76 }
77
78 renderSpanStart(facesContext, component, clientId, value, style, styleClass);
79
80
81
82
83
84
85
86 }
87 }
88
89 protected void renderOutputLinkStart(FacesContext facesContext, UIOutput output) throws IOException
90 {
91
92 if (UserRoleUtils.isEnabledOnUserRole(output))
93 {
94 super.renderOutputLinkStart(facesContext, output);
95 }
96 }
97
98 protected void renderOutputLinkEnd(FacesContext facesContext,
99 UIComponent component) throws IOException
100 {
101 if (UserRoleUtils.isEnabledOnUserRole(component))
102 {
103 super.renderOutputLinkEnd(facesContext, component);
104 }
105 }
106
107 protected void renderCommandLinkEnd(FacesContext facesContext, UIComponent component) throws IOException
108 {
109
110 if (UserRoleUtils.isEnabledOnUserRole(component) &&
111 !((HtmlCommandLink) component).isDisabled() )
112 {
113 super.renderCommandLinkEnd(facesContext, component);
114 }
115 else
116 {
117 renderSpanEnd(facesContext, component);
118 }
119 }
120
121 protected void renderSpanStart(FacesContext facesContext,
122 UIComponent component,
123 String clientId,
124 Object value,
125 String style,
126 String styleClass) throws IOException
127 {
128 ResponseWriter writer = facesContext.getResponseWriter();
129
130 String[] spanAttrsToRender;
131
132 writer.startElement(HTML.SPAN_ELEM, component);
133
134 spanAttrsToRender = HTML.COMMON_PASSTROUGH_ATTRIBUTES_WITHOUT_STYLE;
135
136 HtmlRendererUtils.renderHTMLAttribute(writer, HTML.ID_ATTR, HTML.ID_ATTR, clientId);
137
138 HtmlRendererUtils.renderHTMLAttributes(writer, component,
139 spanAttrsToRender);
140 HtmlRendererUtils.renderHTMLAttribute(writer, HTML.STYLE_ATTR, HTML.STYLE_ATTR,
141 style);
142 HtmlRendererUtils.renderHTMLAttribute(writer, HTML.STYLE_CLASS_ATTR, HTML.STYLE_CLASS_ATTR,
143 styleClass);
144
145
146 if(value != null)
147 {
148 writer.writeText(value.toString(), JSFAttr.VALUE_ATTR);
149 }
150 }
151
152 protected void renderSpanEnd(FacesContext facesContext, UIComponent component) throws IOException
153 {
154 ResponseWriter writer = facesContext.getResponseWriter();
155
156 writer.writeText("", null);
157 writer.endElement(HTML.SPAN_ELEM);
158 }
159 }