initial BindingLifecycle @MVC integration

This commit is contained in:
Keith Donald
2009-07-30 11:18:39 +00:00
parent 44cf4e207a
commit e020b5752a
15 changed files with 891 additions and 8 deletions

View File

@@ -17,11 +17,13 @@
package org.springframework.web.context.request;
import java.security.Principal;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
/**
@@ -63,6 +65,10 @@ public class FacesWebRequest extends FacesRequestAttributes implements NativeWeb
return getExternalContext().getRequestParameterMap().get(paramName);
}
public Iterator<String> getParameterNames() {
return getExternalContext().getRequestParameterNames();
}
public String[] getParameterValues(String paramName) {
return getExternalContext().getRequestParameterValuesMap().get(paramName);
}

View File

@@ -0,0 +1,86 @@
/*
* Copyright 2004-2009 the original author or authors.
*
* 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.
*/
package org.springframework.web.context.request;
import java.util.Iterator;
import org.springframework.core.collection.StringKeyedMapAdapter;
import org.springframework.util.Assert;
/**
* Map backed by a Web request parameter map for accessing request parameters.
* Also provides support for multi-part requests, providing transparent access to the request "fileMap" as a request parameter entry.
* @author Keith Donald
* @since 3.0
*/
public class NativeWebRequestParameterMap extends StringKeyedMapAdapter<Object> {
/**
* The wrapped native request.
*/
private NativeWebRequest request;
/**
* Create a new map wrapping the parameters of given request.
*/
public NativeWebRequestParameterMap(NativeWebRequest request) {
Assert.notNull(request, "The NativeWebRequest is required");
this.request = request;
}
protected Object getAttribute(String key) {
/* TODO - MultipartRequest is NOT accessible b/c its in web.servlet
if (request instanceof MultipartRequest) {
MultipartRequest multipartRequest = (MultipartRequest) request;
Object data = multipartRequest.getFileMap().get(key);
if (data != null) {
return data;
}
}
*/
String[] parameters = request.getParameterValues(key);
if (parameters == null) {
return null;
} else if (parameters.length == 1) {
return parameters[0];
} else {
return parameters;
}
}
protected void setAttribute(String key, Object value) {
throw new UnsupportedOperationException("WebRequest parameter maps are immutable");
}
protected void removeAttribute(String key) {
throw new UnsupportedOperationException("WebRequest parameter maps are immutable");
}
protected Iterator<String> getAttributeNames() {
return request.getParameterNames();
/* TODO - MultipartRequest is NOT accessible b/c its in web.servlet
if (request instanceof MultipartRequest) {
MultipartRequest multipartRequest = (MultipartRequest) request;
CompositeIterator iterator = new CompositeIterator();
iterator.add(multipartRequest.getFileMap().keySet().iterator());
iterator.add(CollectionUtils.toIterator(request.getParameterNames()));
return iterator;
} else {
return CollectionUtils.toIterator(request.getParameterNames());
}
*/
}
}

View File

@@ -17,12 +17,14 @@
package org.springframework.web.context.request;
import java.security.Principal;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -97,6 +99,11 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
return getRequest().getParameterValues(paramName);
}
@SuppressWarnings("unchecked")
public Iterator<String> getParameterNames() {
return CollectionUtils.toIterator(getRequest().getParameterNames());
}
@SuppressWarnings("unchecked")
public Map<String, String[]> getParameterMap() {
return getRequest().getParameterMap();

View File

@@ -17,6 +17,7 @@
package org.springframework.web.context.request;
import java.security.Principal;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
@@ -61,6 +62,13 @@ public interface WebRequest extends RequestAttributes {
*/
String[] getParameterValues(String paramName);
/**
* Return a Iterator over request parameter names.
* @see javax.servlet.http.HttpServletRequest#getParameterNames()
* @since 3.0
*/
Iterator<String> getParameterNames();
/**
* Return a immutable Map of the request parameters, with parameter names as map keys
* and parameter values as map values. The map values will be of type String array.