You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2006/07/08 08:37:28 UTC
svn commit: r420056 - in /myfaces/tobago/trunk:
core/src/main/java/org/apache/myfaces/tobago/ajax/api/
core/src/main/java/org/apache/myfaces/tobago/application/
core/src/main/java/org/apache/myfaces/tobago/util/
theme/scarborough/src/main/java/org/apac...
Author: bommel
Date: Fri Jul 7 23:37:27 2006
New Revision: 420056
URL: http://svn.apache.org/viewvc?rev=420056&view=rev
Log:
[TOBAGO-94] encode inputsuggest content with response writer
Added:
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/RequestUtils.java
Modified:
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxPhaseListener.java
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/application/ViewHandlerImpl.java
myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/InRenderer.java
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxPhaseListener.java?rev=420056&r1=420055&r2=420056&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxPhaseListener.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxPhaseListener.java Fri Jul 7 23:37:27 2006
@@ -19,6 +19,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.myfaces.tobago.context.ResourceManagerUtil;
+import org.apache.myfaces.tobago.util.RequestUtils;
import javax.faces.FactoryFinder;
import javax.faces.application.StateManager;
@@ -93,7 +94,7 @@
+ externalContext.getRequestParameterMap().get(AJAX_COMPONENT_ID));
}
-
+ RequestUtils.ensureEncoding(externalContext);
final UIViewRoot viewRoot = facesContext.getViewRoot();
StringWriter content = new StringWriter();
RenderKitFactory renderFactory = (RenderKitFactory)
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/application/ViewHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/application/ViewHandlerImpl.java?rev=420056&r1=420055&r2=420056&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/application/ViewHandlerImpl.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/application/ViewHandlerImpl.java Fri Jul 7 23:37:27 2006
@@ -22,6 +22,7 @@
import org.apache.myfaces.tobago.component.ComponentUtil;
import org.apache.myfaces.tobago.context.ClientProperties;
import org.apache.myfaces.tobago.webapp.TobagoResponse;
+import org.apache.myfaces.tobago.util.RequestUtils;
import javax.faces.FacesException;
import javax.faces.application.ViewHandler;
@@ -32,7 +33,6 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
import java.util.Locale;
public class ViewHandlerImpl extends ViewHandler {
@@ -162,26 +162,13 @@
}
// this is only needed in the first request, the later will be handled by faces
// TODO: maybe find a way to make this unneeded
- handleEncoding(facesContext);
+ RequestUtils.ensureEncoding(facesContext.getExternalContext());
UIViewRoot viewRoot = base.restoreView(facesContext, viewId);
ensureClientProperties(facesContext, viewRoot);
return viewRoot;
}
- private void handleEncoding(FacesContext facesContext) {
- try {
- if (facesContext.getExternalContext().getRequest() instanceof HttpServletRequest) {
- HttpServletRequest request =
- (HttpServletRequest) facesContext.getExternalContext().getRequest();
- if (request.getCharacterEncoding() == null) {
- request.setCharacterEncoding("UTF-8");
- }
- }
- // TODO PortletRequest
- } catch (UnsupportedEncodingException e) {
- LOG.error("" + e, e);
- }
- }
+
public void writeState(FacesContext facesContext) throws IOException {
base.writeState(facesContext);
Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/RequestUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/RequestUtils.java?rev=420056&view=auto
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/RequestUtils.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/util/RequestUtils.java Fri Jul 7 23:37:27 2006
@@ -0,0 +1,56 @@
+package org.apache.myfaces.tobago.util;
+
+/*
+ * Copyright 2002-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.faces.context.FacesContext;
+import javax.faces.context.ExternalContext;
+import javax.servlet.http.HttpServletRequest;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: bommel
+ * Date: 03.07.2006
+ * Time: 21:19:38
+ * To change this template use File | Settings | File Templates.
+ */
+public class RequestUtils {
+
+ private static final Log LOG = LogFactory.getLog(RequestUtils.class);
+
+ public static void ensureEncoding(ExternalContext externalContext) {
+ try {
+ if (externalContext.getRequest() instanceof HttpServletRequest) {
+ HttpServletRequest request =
+ (HttpServletRequest) externalContext.getRequest();
+ System.err.println("=========================================");
+ if (request.getCharacterEncoding() == null) {
+ request.setCharacterEncoding("UTF-8");
+ System.err.println("Setting to utf-8 ");
+ } else {
+ System.err.println(request.getCharacterEncoding());
+ }
+ }
+ // TODO PortletRequest
+ } catch (UnsupportedEncodingException e) {
+ LOG.error("" + e, e);
+ }
+ }
+}
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/InRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/InRenderer.java?rev=420056&r1=420055&r2=420056&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/InRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/InRenderer.java Fri Jul 7 23:37:27 2006
@@ -168,7 +168,8 @@
return;
}
-
+ TobagoResponseWriter writer
+ = (TobagoResponseWriter) context.getResponseWriter();
int maxSuggestedCount = 25; //input.getMaxSuggestedItems()!=null
// ? input.getMaxSuggestedItems().intValue()
// : DEFAULT_MAX_SUGGESTED_ITEMS;
@@ -176,23 +177,17 @@
List suggesteds = (List) mb.invoke(context, new Object[]{
AjaxPhaseListener.getValueForComponent(context, uiComponent)});
-
- StringBuffer buf = new StringBuffer();
- buf.append("<ul>");
-
+ writer.startElement("ul", null);
int suggestedCount = 0;
for (Iterator i = suggesteds.iterator(); i.hasNext(); suggestedCount++) {
if (suggestedCount > maxSuggestedCount) {
break;
}
-
- buf.append("<li>");
- buf.append(i.next().toString());
- buf.append("</li>");
+ writer.startElement("li", null);
+ writer.writeText(i.next(), null);
+ writer.endElement("li");
}
- buf.append("</ul>");
-
- context.getResponseWriter().write(buf.toString());
+ writer.endElement("ul");
context.responseComplete();
}