fixes for known 2.0.0 bugs reported since release - see changelog
This commit is contained in:
@@ -21,7 +21,7 @@ import java.util.List;
|
||||
import javax.faces.model.DataModel;
|
||||
|
||||
import org.springframework.binding.convert.Converter;
|
||||
import org.springframework.binding.convert.converters.AbstractConverter;
|
||||
import org.springframework.faces.model.OneSelectionTrackingListDataModel;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
@@ -30,14 +30,7 @@ import org.springframework.util.ClassUtils;
|
||||
*
|
||||
* @author Jeremy Grelle
|
||||
*/
|
||||
public class DataModelConverter extends AbstractConverter {
|
||||
|
||||
protected Object doConvert(Object source, Class targetClass, Object context) throws Exception {
|
||||
Constructor emptyConstructor = ClassUtils.getConstructorIfAvailable(targetClass, new Class[] {});
|
||||
DataModel model = (DataModel) emptyConstructor.newInstance(new Object[] {});
|
||||
model.setWrappedData(source);
|
||||
return model;
|
||||
}
|
||||
public class DataModelConverter implements Converter {
|
||||
|
||||
public Class[] getSourceClasses() {
|
||||
return new Class[] { Object[].class, List.class, Object.class };
|
||||
@@ -47,4 +40,14 @@ public class DataModelConverter extends AbstractConverter {
|
||||
return new Class[] { DataModel.class };
|
||||
}
|
||||
|
||||
public Object convert(Object source, Class targetClass, Object context) throws Exception {
|
||||
if (targetClass.equals(DataModel.class)) {
|
||||
targetClass = OneSelectionTrackingListDataModel.class;
|
||||
}
|
||||
Constructor emptyConstructor = ClassUtils.getConstructorIfAvailable(targetClass, new Class[] {});
|
||||
DataModel model = (DataModel) emptyConstructor.newInstance(new Object[] {});
|
||||
model.setWrappedData(source);
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ e.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package org.springframework.faces.model.converter;
|
||||
|
||||
import javax.faces.model.DataModel;
|
||||
|
||||
import org.springframework.binding.convert.ConversionService;
|
||||
import org.springframework.binding.convert.converters.TextToClass;
|
||||
import org.springframework.binding.convert.service.DefaultConversionService;
|
||||
@@ -37,6 +39,6 @@ public class FacesConversionService extends DefaultConversionService {
|
||||
protected void addFacesConverters() {
|
||||
addConverter(new DataModelConverter());
|
||||
TextToClass classConverter = (TextToClass) getConverter(String.class, Class.class);
|
||||
classConverter.addAlias("dataModel", OneSelectionTrackingListDataModel.class);
|
||||
classConverter.addAlias("dataModel", DataModel.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.springframework.faces.config;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.binding.convert.ConversionException;
|
||||
import org.springframework.binding.convert.ConversionExecutionException;
|
||||
import org.springframework.binding.convert.ConversionExecutor;
|
||||
import org.springframework.binding.convert.ConversionService;
|
||||
import org.springframework.binding.expression.Expression;
|
||||
@@ -74,21 +74,21 @@ public class FacesFlowBuilderServicesBeanDefinitionParserTests extends TestCase
|
||||
|
||||
public static class TestConversionService implements ConversionService {
|
||||
|
||||
public Class getClassByAlias(String alias) throws ConversionException {
|
||||
public Class getClassByAlias(String alias) throws ConversionExecutionException {
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public ConversionExecutor getConversionExecutor(Class sourceClass, Class targetClass)
|
||||
throws ConversionException {
|
||||
throws ConversionExecutionException {
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public ConversionExecutor getConversionExecutorByTargetAlias(Class sourceClass, String targetAlias)
|
||||
throws ConversionException {
|
||||
throws ConversionExecutionException {
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public ConversionExecutor[] getConversionExecutorsForSource(Class sourceClass) throws ConversionException {
|
||||
public ConversionExecutor[] getConversionExecutorsForSource(Class sourceClass) throws ConversionExecutionException {
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
|
||||
@@ -7,16 +7,25 @@ import java.util.List;
|
||||
import javax.faces.model.DataModel;
|
||||
import javax.faces.model.ListDataModel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.binding.convert.Converter;
|
||||
import org.springframework.faces.model.SerializableListDataModel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class DataModelConverterTests extends TestCase {
|
||||
|
||||
Converter converter = new DataModelConverter();
|
||||
|
||||
public void testConvertListToListDataModel() {
|
||||
public void testConvertListToDataModel() throws Exception {
|
||||
List sourceList = new ArrayList();
|
||||
|
||||
DataModel resultModel = (DataModel) converter.convert(sourceList, DataModel.class, null);
|
||||
|
||||
assertNotNull(resultModel);
|
||||
assertSame(sourceList, resultModel.getWrappedData());
|
||||
}
|
||||
|
||||
public void testConvertListToListDataModel() throws Exception {
|
||||
List sourceList = new ArrayList();
|
||||
|
||||
DataModel resultModel = (DataModel) converter.convert(sourceList, ListDataModel.class, null);
|
||||
@@ -25,7 +34,7 @@ public class DataModelConverterTests extends TestCase {
|
||||
assertSame(sourceList, resultModel.getWrappedData());
|
||||
}
|
||||
|
||||
public void testConvertListToSerializableListDataModel() {
|
||||
public void testConvertListToSerializableListDataModel() throws Exception {
|
||||
List sourceList = new ArrayList();
|
||||
|
||||
DataModel resultModel = (DataModel) converter.convert(sourceList, SerializableListDataModel.class, null);
|
||||
@@ -35,7 +44,7 @@ public class DataModelConverterTests extends TestCase {
|
||||
assertTrue(resultModel instanceof Serializable);
|
||||
}
|
||||
|
||||
public void testConvertListToSerializableListDataModelNullSource() {
|
||||
public void testConvertListToSerializableListDataModelNullSource() throws Exception {
|
||||
List sourceList = null;
|
||||
|
||||
DataModel resultModel = (DataModel) converter.convert(sourceList, SerializableListDataModel.class, null);
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.springframework.faces.model.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.model.DataModel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.binding.convert.ConversionExecutor;
|
||||
|
||||
public class FacesConversionServiceTests extends TestCase {
|
||||
private FacesConversionService service;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
service = new FacesConversionService();
|
||||
}
|
||||
|
||||
public void testGetAbstractType() {
|
||||
ConversionExecutor executor = service.getConversionExecutor(List.class, DataModel.class);
|
||||
ArrayList list = new ArrayList();
|
||||
list.add("foo");
|
||||
executor.execute(list);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user