01: /*
02: * Copyright 2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.taglib.core;
17:
18: import javax.faces.webapp.UIComponentELTag;
19: import javax.faces.component.UIComponent;
20: import javax.faces.component.UINamingContainer;
21: import javax.faces.component.UIOutput;
22: import javax.faces.context.FacesContext;
23:
24: import org.apache.myfaces.application.jsp.ViewResponseWrapper;
25:
26: /**
27: * @author Thomas Spiegl (latest modification by $Author: matzew $)
28: * @version $Revision: 521670 $ $Date: 2007-03-23 12:04:26 +0100 (Fr, 23 Mrz 2007) $
29: */
30: public class SubviewTag extends UIComponentELTag {
31: public SubviewTag() {
32: super ();
33: }
34:
35: public String getComponentType() {
36: return UINamingContainer.COMPONENT_TYPE;
37: }
38:
39: public String getRendererType() {
40: return null;
41: }
42:
43: /**
44: * Creates a UIComponent from the BodyContent
45: * If a Subview is included via the <jsp:include> tag
46: * the corresponding jsp is rendered with
47: * getServletContext().getRequestDispatcher("includedSite").include(request,response)
48: * and it is possible that something was written to the Response direct.
49: * So is is necessary that the content of the wrapped response is added to the componenttree.
50: * @return UIComponent or null
51: */
52: protected UIComponent createVerbatimComponentFromBodyContent() {
53: UIOutput component = (UIOutput) super
54: .createVerbatimComponentFromBodyContent();
55: FacesContext facesContext = FacesContext.getCurrentInstance();
56: Object response = facesContext.getExternalContext()
57: .getResponse();
58: String wrappedOutput;
59:
60: if (response instanceof ViewResponseWrapper) {
61: ViewResponseWrapper wrappedResponse = (ViewResponseWrapper) response;
62: wrappedOutput = wrappedResponse.toString();
63: if (wrappedOutput.length() > 0) {
64: String componentvalue = null;
65: if (component != null) {
66: //save the Value of the Bodycontent
67: componentvalue = (String) component.getValue();
68: }
69: component = super.createVerbatimComponent();
70: if (componentvalue != null) {
71: component.setValue(wrappedOutput + componentvalue);
72: } else {
73: component.setValue(wrappedOutput);
74: }
75: wrappedResponse.reset();
76: }
77: }
78: return component;
79: }
80:
81: }
|