Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SubviewTag |
|
| 2.0;2 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, | |
13 | * software distributed under the License is distributed on an | |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | * KIND, either express or implied. See the License for the | |
16 | * specific language governing permissions and limitations | |
17 | * under the License. | |
18 | */ | |
19 | package org.apache.myfaces.taglib.core; | |
20 | ||
21 | import javax.faces.webapp.UIComponentELTag; | |
22 | import javax.faces.component.UIComponent; | |
23 | import javax.faces.component.UINamingContainer; | |
24 | import javax.faces.component.UIOutput; | |
25 | import javax.faces.context.FacesContext; | |
26 | ||
27 | import org.apache.myfaces.application.jsp.ViewResponseWrapper; | |
28 | import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspTag; | |
29 | ||
30 | /** | |
31 | * @author Thomas Spiegl (latest modification by $Author: lu4242 $) | |
32 | * @version $Revision: 693358 $ $Date: 2008-09-08 22:54:29 -0500 (Mon, 08 Sep 2008) $ | |
33 | */ | |
34 | public class SubviewTag extends UIComponentELTag | |
35 | { | |
36 | public SubviewTag() { | |
37 | 0 | super(); |
38 | 0 | } |
39 | ||
40 | public String getComponentType() | |
41 | { | |
42 | 0 | return UINamingContainer.COMPONENT_TYPE; |
43 | } | |
44 | ||
45 | public String getRendererType() | |
46 | { | |
47 | 0 | return null; |
48 | } | |
49 | ||
50 | /** | |
51 | * Creates a UIComponent from the BodyContent | |
52 | * If a Subview is included via the <jsp:include> tag | |
53 | * the corresponding jsp is rendered with | |
54 | * getServletContext().getRequestDispatcher("includedSite").include(request,response) | |
55 | * and it is possible that something was written to the Response direct. | |
56 | * So is is necessary that the content of the wrapped response is added to the componenttree. | |
57 | * @return UIComponent or null | |
58 | */ | |
59 | protected UIComponent createVerbatimComponentFromBodyContent() { | |
60 | 0 | UIOutput component = (UIOutput) super.createVerbatimComponentFromBodyContent(); |
61 | 0 | FacesContext facesContext = FacesContext.getCurrentInstance(); |
62 | 0 | Object response = facesContext.getExternalContext().getResponse(); |
63 | String wrappedOutput; | |
64 | ||
65 | 0 | if (response instanceof ViewResponseWrapper) |
66 | { | |
67 | 0 | ViewResponseWrapper wrappedResponse = (ViewResponseWrapper) response; |
68 | 0 | wrappedOutput = wrappedResponse.toString(); |
69 | 0 | if (wrappedOutput != null && wrappedOutput.length() > 0) |
70 | { | |
71 | 0 | String componentvalue = null; |
72 | 0 | if (component != null) |
73 | { | |
74 | //save the Value of the Bodycontent | |
75 | 0 | componentvalue = (String) component.getValue(); |
76 | } | |
77 | 0 | component = super.createVerbatimComponent(); |
78 | 0 | if (componentvalue != null) |
79 | { | |
80 | 0 | component.setValue(wrappedOutput + componentvalue); |
81 | } | |
82 | else | |
83 | { | |
84 | 0 | component.setValue(wrappedOutput); |
85 | } | |
86 | 0 | wrappedResponse.reset(); |
87 | } | |
88 | } | |
89 | 0 | return component; |
90 | } | |
91 | ||
92 | } |