Source Code Cross Referenced for HtmlResponseStateManager.java in  » J2EE » myfaces-core-1.2.0 » org » apache » myfaces » renderkit » html » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » myfaces core 1.2.0 » org.apache.myfaces.renderkit.html 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004-2006 The Apache Software Foundation.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.apache.myfaces.renderkit.html;
017:
018:        import org.apache.commons.logging.Log;
019:        import org.apache.commons.logging.LogFactory;
020:        import org.apache.myfaces.renderkit.MyfacesResponseStateManager;
021:        import org.apache.myfaces.shared_impl.renderkit.html.HTML;
022:        import org.apache.myfaces.shared_impl.util.StateUtils;
023:
024:        import javax.faces.application.StateManager;
025:        import javax.faces.context.FacesContext;
026:        import javax.faces.context.ResponseWriter;
027:        import javax.faces.render.RenderKitFactory;
028:        import javax.faces.render.ResponseStateManager;
029:        import java.io.IOException;
030:        import java.util.Map;
031:
032:        /**
033:         * @author Manfred Geiler (latest modification by $Author: baranda $)
034:         * @version $Revision: 495909 $ $Date: 2007-01-13 16:27:05 +0100 (Sa, 13 Jan 2007) $
035:         */
036:        public class HtmlResponseStateManager extends
037:                MyfacesResponseStateManager {
038:            private static final Log log = LogFactory
039:                    .getLog(HtmlResponseStateManager.class);
040:
041:            private static final int TREE_PARAM = 0;
042:            private static final int STATE_PARAM = 1;
043:            private static final int VIEWID_PARAM = 2;
044:
045:            public static final String STANDARD_STATE_SAVING_PARAM = "javax.faces.ViewState";
046:
047:            public void writeState(FacesContext facescontext,
048:                    StateManager.SerializedView serializedview)
049:                    throws IOException {
050:                ResponseWriter responseWriter = facescontext
051:                        .getResponseWriter();
052:
053:                Object[] savedState = new Object[3];
054:
055:                if (facescontext.getApplication().getStateManager()
056:                        .isSavingStateInClient(facescontext)) {
057:                    if (log.isTraceEnabled())
058:                        log.trace("Writing state in client");
059:                    Object treeStruct = serializedview.getStructure();
060:                    Object compStates = serializedview.getState();
061:
062:                    if (treeStruct != null) {
063:                        savedState[TREE_PARAM] = treeStruct;
064:                    } else {
065:                        log
066:                                .error("No tree structure to be saved in client response!");
067:                    }
068:
069:                    if (compStates != null) {
070:                        savedState[STATE_PARAM] = compStates;
071:                    } else {
072:                        log
073:                                .error("No component states to be saved in client response!");
074:                    }
075:                } else {
076:                    if (log.isTraceEnabled())
077:                        log.trace("Writing state in server");
078:                    // write viewSequence
079:                    Object treeStruct = serializedview.getStructure();
080:                    if (treeStruct != null) {
081:                        if (treeStruct instanceof  String) {
082:                            savedState[TREE_PARAM] = treeStruct;
083:                        }
084:                    }
085:                }
086:
087:                savedState[VIEWID_PARAM] = facescontext.getViewRoot()
088:                        .getViewId();
089:
090:                if (log.isTraceEnabled())
091:                    log.trace("Writing view state and renderKit fields");
092:
093:                // write the view state field
094:                writeViewStateField(facescontext, responseWriter, savedState);
095:
096:                // renderKitId field
097:                writeRenderKitIdField(facescontext, responseWriter);
098:            }
099:
100:            private void writeViewStateField(FacesContext facesContext,
101:                    ResponseWriter responseWriter, Object savedState)
102:                    throws IOException {
103:                responseWriter.startElement(HTML.INPUT_ELEM, null);
104:                responseWriter.writeAttribute(HTML.TYPE_ATTR,
105:                        HTML.INPUT_TYPE_HIDDEN, null);
106:                responseWriter.writeAttribute(HTML.NAME_ATTR,
107:                        STANDARD_STATE_SAVING_PARAM, null);
108:                responseWriter.writeAttribute(HTML.ID_ATTR,
109:                        STANDARD_STATE_SAVING_PARAM, null);
110:                responseWriter.writeAttribute(HTML.VALUE_ATTR, StateUtils
111:                        .construct(savedState, facesContext
112:                                .getExternalContext()), null);
113:                responseWriter.endElement(HTML.INPUT_ELEM);
114:            }
115:
116:            private void writeRenderKitIdField(FacesContext facesContext,
117:                    ResponseWriter responseWriter) throws IOException {
118:
119:                String defaultRenderKitId = facesContext.getApplication()
120:                        .getDefaultRenderKitId();
121:                if (defaultRenderKitId != null
122:                        && !RenderKitFactory.HTML_BASIC_RENDER_KIT
123:                                .equals(defaultRenderKitId)) {
124:                    responseWriter.startElement(HTML.INPUT_ELEM, null);
125:                    responseWriter.writeAttribute(HTML.TYPE_ATTR,
126:                            HTML.INPUT_TYPE_HIDDEN, null);
127:                    responseWriter.writeAttribute(HTML.NAME_ATTR,
128:                            ResponseStateManager.RENDER_KIT_ID_PARAM, null);
129:                    responseWriter.writeAttribute(HTML.VALUE_ATTR,
130:                            defaultRenderKitId, null);
131:                    responseWriter.endElement(HTML.INPUT_ELEM);
132:                }
133:            }
134:
135:            public Object getTreeStructureToRestore(FacesContext facesContext,
136:                    String viewId) {
137:                Map reqParamMap = facesContext.getExternalContext()
138:                        .getRequestParameterMap();
139:
140:                Object encodedState = reqParamMap
141:                        .get(STANDARD_STATE_SAVING_PARAM);
142:
143:                if (encodedState == null)
144:                    return null;
145:
146:                Object[] savedState = (Object[]) StateUtils.reconstruct(
147:                        (String) encodedState, facesContext
148:                                .getExternalContext());
149:
150:                String restoredViewId = (String) savedState[VIEWID_PARAM];
151:
152:                if (restoredViewId == null || !restoredViewId.equals(viewId)) {
153:                    //no saved state or state of different viewId
154:                    if (log.isTraceEnabled())
155:                        log
156:                                .trace("No saved state or state of a different viewId"
157:                                        + restoredViewId);
158:                    return null;
159:                }
160:
161:                return savedState[TREE_PARAM];
162:            }
163:
164:            public Object getComponentStateToRestore(FacesContext facesContext) {
165:                Map reqParamMap = facesContext.getExternalContext()
166:                        .getRequestParameterMap();
167:
168:                Object encodedState = reqParamMap
169:                        .get(STANDARD_STATE_SAVING_PARAM);
170:
171:                if (encodedState == null)
172:                    return null;
173:
174:                Object[] savedState = (Object[]) StateUtils.reconstruct(
175:                        (String) encodedState, facesContext
176:                                .getExternalContext());
177:
178:                String restoredViewId = (String) savedState[VIEWID_PARAM];
179:
180:                if (restoredViewId == null) {
181:                    //no saved state or state of different viewId
182:                    if (log.isTraceEnabled())
183:                        log
184:                                .trace("No saved state or state of a different viewId: "
185:                                        + restoredViewId);
186:                    return null;
187:                }
188:
189:                return savedState[STATE_PARAM];
190:            }
191:
192:            /**
193:             * Checks if the current request is a postback
194:             * @since 1.2
195:             */
196:            @Override
197:            public boolean isPostback(FacesContext context) {
198:                return context.getExternalContext().getRequestParameterMap()
199:                        .containsKey(ResponseStateManager.VIEW_STATE_PARAM);
200:            }
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.