01: package ru.emdev.EmForge.web.renderer;
02:
03: /**
04: * Copyright 2004-2005 The Apache Software Foundation.
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18: import javax.faces.render.Renderer;
19:
20: /** This version of s:focus renderer is fully based on the HtmlFocusRenderer,
21: * but simple removed Dojo-usage (I do not know why it is required)
22: */
23: public class HtmlFocusRenderer extends Renderer {
24: /** TODO !!!
25: private static Log log = LogFactory.getLog(HtmlFocus.class);
26:
27: public void decode(FacesContext facesContext, UIComponent component)
28: {
29: RendererUtils.checkParamValidity(facesContext, component, HtmlFocus.class);
30:
31: HtmlFocus focus = (HtmlFocus) component;
32:
33: if(focus.isRememberClientFocus())
34: {
35: focus.setSubmittedValue(RendererUtils.getStringValue(facesContext, component));
36: }
37: }
38:
39: public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
40: throws IOException
41: {
42: RendererUtils.checkParamValidity(facesContext, uiComponent,
43: HtmlFocus.class);
44:
45: HtmlFocus focus = (HtmlFocus) uiComponent;
46:
47: UIComponent targetComponent = findUIComponent(focus);
48:
49: if(targetComponent != null)
50: {
51: String clientId = targetComponent.getClientId(facesContext);
52:
53: ResponseWriter writer = facesContext.getResponseWriter();
54:
55: writer.startElement(HTML.SCRIPT_ELEM, uiComponent);
56: writer.writeAttribute(HTML.SCRIPT_TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
57: writer.writeText("document.getElementById('" + clientId + "').focus()", null);
58: writer.endElement(HTML.SCRIPT_ELEM);
59:
60: writer.startElement(HTML.INPUT_ELEM, uiComponent);
61: writer.writeAttribute(HTML.TYPE_ATTR,HTML.INPUT_TYPE_HIDDEN,null);
62: writer.writeAttribute(HTML.ID_ATTR,uiComponent.getClientId(facesContext), JSFAttr.ID_ATTR);
63: writer.writeAttribute(HTML.VALUE_ATTR,clientId,JSFAttr.VALUE_ATTR);
64: writer.endElement(HTML.INPUT_ELEM);
65: }
66: }
67: */
68:
69: /** Since focus.findUIComponent is protected, it is not available here
70: * So, we should implement own method (copy from focus) here
71: * @param i_focus
72: * @return
73: */
74: /*
75: protected UIComponent findUIComponent(HtmlFocus i_focus)
76: {
77: String forStr = i_focus.getFor();
78:
79: if (forStr == null)
80: {
81: throw new IllegalArgumentException("focus@for must be specified");
82: }
83:
84: UIComponent forComp = i_focus.findComponent(forStr);
85: if (forComp == null)
86: {
87: log.warn("could not find UIComponent referenced by attribute focus@for = '"
88: + forStr + "'");
89: }
90: return forComp;
91: }
92: */
93:
94: }
|