[jboss-user] [JBoss Seam] - Re: NPE in Param.validateConvertedValue
pgmjsd
do-not-reply at jboss.com
Mon Jan 28 09:28:48 EST 2008
I was able to fix this by initializing the 'invalidValues' field to a zero length array inside Validators.ValidatingResolver's constructor. I added it to my application, overriding the existing Seam component:
| package com.foo.seam;
|
| import org.hibernate.validator.ClassValidator;
| import org.hibernate.validator.InvalidValue;
| import org.jboss.seam.Component;
| import org.jboss.seam.Instance;
| import org.jboss.seam.ScopeType;
| import org.jboss.seam.core.SeamResourceBundle;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.Scope;
| import org.jboss.seam.annotations.intercept.BypassInterceptors;
| import org.jboss.seam.contexts.Contexts;
| import org.jboss.seam.el.EL;
|
| import javax.el.ELContext;
| import javax.el.ELException;
| import javax.el.ELResolver;
| import javax.el.PropertyNotFoundException;
| import javax.el.PropertyNotWritableException;
| import javax.el.ValueExpression;
| import java.beans.FeatureDescriptor;
| import java.util.Iterator;
| import java.util.Locale;
| import java.util.Map;
| import java.util.concurrent.ConcurrentHashMap;
|
| /**
| * Caches instances of Hibernate Validator ClassValidator
| *
| * @author Gavin King
| * @author Josh - patched up the inner class.
| */
| @Name("org.jboss.seam.core.validators")
| @BypassInterceptors
| @Scope(ScopeType.APPLICATION)
| public class Validators extends org.jboss.seam.core.Validators
| {
|
| /**
| * Validate that the given value can be assigned to the property given by the value
| * expression.
| *
| * @param valueExpression a value expression, referring to a property
| * @param elContext the ELContext in which to evaluate the expression
| * @param value a value to be assigned to the property
| * @return a set of potential InvalidValues, from Hibernate Validator
| */
| public InvalidValue[] validate(ValueExpression valueExpression, ELContext elContext, Object value)
| {
| ValidatingResolver validatingResolver = new ValidatingResolver( elContext.getELResolver() );
| ELContext decoratedContext = EL.createELContext(elContext, validatingResolver);
| valueExpression.setValue(decoratedContext, value);
| return validatingResolver.getInvalidValues();
| }
|
| class ValidatingResolver extends ELResolver
| {
| private ELResolver delegate;
| private InvalidValue[] invalidValues;
|
| public ValidatingResolver(ELResolver delegate)
| {
| this.delegate = delegate;
| invalidValues = new InvalidValue[0]; // <== Initialize array.
| }
|
| public InvalidValue[] getInvalidValues()
| {
| return invalidValues;
| }
|
| @Override
| public Class<?> getCommonPropertyType(ELContext context, Object value)
| {
| return delegate.getCommonPropertyType(context, value);
| }
|
| @Override
| public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object value)
| {
| return delegate.getFeatureDescriptors(context, value);
| }
|
| @Override
| public Class<?> getType(ELContext context, Object x, Object y)
| throws NullPointerException, PropertyNotFoundException, ELException
| {
| return delegate.getType(context, x, y);
| }
|
| @Override
| public Object getValue(ELContext context, Object base, Object property)
| throws NullPointerException, PropertyNotFoundException, ELException
| {
| return delegate.getValue(context, base, property);
| }
|
| @Override
| public boolean isReadOnly(ELContext context, Object base, Object property)
| throws NullPointerException, PropertyNotFoundException, ELException
| {
| return delegate.isReadOnly(context, base, property);
| }
|
| @Override
| public void setValue(ELContext context, Object base, Object property, Object value)
| throws NullPointerException, PropertyNotFoundException, PropertyNotWritableException, ELException
| {
| if (base!=null && property!=null )
| {
| context.setPropertyResolved(true);
| invalidValues = getValidator(base).getPotentialInvalidValues( property.toString(), value );
| }
| }
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4124073#4124073
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4124073
More information about the jboss-user
mailing list