I'm going to change it to treat undefined as null. In theory, I could change
RecordJsoImpl to initialize all property fields to null or a default value,
 according to JLS semantics, but this just makes the client code bigger, and
JSON transfers bigger. Anyone object?

-Ray


On Fri, Aug 6, 2010 at 2:50 PM, Ray Cromwell <[email protected]> wrote:

>
> Thanks for finding this, you just saved me a lot of trouble tracking it
> down. I will fix it shortly.
>
> -Ray
>
>
> On Fri, Aug 6, 2010 at 2:31 PM, pjulien <[email protected]> wrote:
>
>> I'm not having much luck with this patch either.  The problem I have
>> is with enums.
>>
>> If I have a record with:
>>
>> Property<PhoneType> phoneType = new
>> EnumProperty<PhoneType>("phoneType", PhoneType.class,
>> PhoneType.values());
>>
>> This works well if the row is created on the server and sent to the
>> client.  The use case is simple:
>>
>> final Column<PhoneHandle, String> phoneTypeColumn = new
>> Column<PhoneHandle, String>(new
>> SelectionCell(translator.allValuesAsStrings())) {
>>    @Override
>>    public String getValue(final PhoneHandle object) {
>>        return
>> translator.getPhoneTypeToString(object.get(object.phoneType));
>>    }
>> };
>>
>> And if the row is generated on the server, again this works well, but
>> if the row was created using request factory (r8495), it just blows
>> up:
>>
>> In RecordJsoImpl.get(), this eventually leads to:
>>
>>  if (property instanceof EnumProperty) {
>>      EnumProperty<V> eProperty = (EnumProperty<V>) property;
>>      Enum[] values = (Enum[]) eProperty.getValues();
>>      int ordinal = getInt(property.getName());
>>
>> And here this blows up in hosted mode saying
>>
>> Caused by: com.google.gwt.dev.shell.HostedModeException: Something
>> other than
>> an int was returned from JSNI method
>> '@com.google.gwt.valuestore.shared.impl.RecordJsoImpl::getInt(Ljava/
>> lang/String;)':
>> JS value of type undefined, expected int
>>
>> but if the row was created on the server, than it just returns a
>> proper integer
>>
>>
>> On Aug 6, 12:48 am, [email protected] wrote:
>> > Revision: 8484
>> > Author: [email protected]
>> > Date: Wed Aug  4 22:08:44 2010
>> > Log: Fix support for null fields and Boolean type types in
>> RequestFactory.
>> > Null fix patch by icsy
>> >
>> > Review athttp://gwt-code-reviews.appspot.com/739801
>> >
>> > Review by: [email protected]://
>> code.google.com/p/google-web-toolkit/source/detail?r=8484
>> >
>> > Added:
>> >
>> >
>> /trunk/user/src/com/google/gwt/requestfactory/client/impl/AbstractBooleanRe
>> quest.java
>> > Modified:
>> >
>> >
>> /trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryGenerato
>> r.java
>> >
>> >
>> /trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.j
>> ava
>> >
>> /trunk/user/src/com/google/gwt/valuestore/shared/impl/RecordJsoImpl.java
>> >
>> >
>> /trunk/user/test/com/google/gwt/requestfactory/server/JsonRequestProcessorT
>> est.java
>> >   /trunk/user/test/com/google/gwt/valuestore/server/SimpleFoo.java
>> >   /trunk/user/test/com/google/gwt/valuestore/shared/SimpleFooRecord.java
>> >
>> >
>> /trunk/user/test/com/google/gwt/valuestore/shared/impl/SimpleFooRecordImpl.
>> java
>> >
>> > =======================================
>> > --- /dev/null
>> > +++
>> >
>> /trunk/user/src/com/google/gwt/requestfactory/client/impl/AbstractBooleanRe
>> quest.java
>> > Wed Aug  4 22:08:44 2010
>> > @@ -0,0 +1,48 @@
>> > +/*
>> > + * Copyright 2010 Google Inc.
>> > + *
>> > + * 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 com.google.gwt.requestfactory.client.impl;
>> > +
>> > +import com.google.gwt.valuestore.shared.SyncResult;
>> > +
>> > +import java.util.Collections;
>> > +
>> > +/**
>> > + * <p>
>> > + * <span style="color:red">Experimental API: This class is still under
>>
>> > rapid
>> > + * development, and is very likely to be deleted. Use it at your own
>> risk.
>> > + * </span>
>> > + * </p>
>> > + * Abstract implementation of
>> > + * {...@link
>> com.google.gwt.requestfactory.shared.RequestFactory.RequestObject
>> > + * RequestFactory.RequestObject} for requests that return Boolean.
>> > + */
>> > +public abstract class AbstractBooleanRequest extends
>> > +    AbstractRequest<Boolean, AbstractBooleanRequest> {
>> > +
>> > +  public AbstractBooleanRequest(RequestFactoryJsonImpl requestFactory)
>> {
>> > +    super(requestFactory);
>> > +  }
>> > +
>> > +  public void handleResponseText(String responseText) {
>> > +    receiver.onSuccess(Boolean.valueOf(responseText),
>> > +        Collections.<SyncResult> emptySet());
>> > +  }
>> > +
>> > +  @Override
>> > +  protected AbstractBooleanRequest getThis() {
>> > +    return this;
>> > +  }
>> > +}
>> > =======================================
>> > ---
>> >
>> /trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryGenerato
>> r.java
>> > Mon Aug  2 15:57:18 2010
>> > +++
>> >
>> /trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryGenerato
>> r.java
>> > Wed Aug  4 22:08:44 2010
>> > @@ -28,6 +28,7 @@
>> >   import com.google.gwt.core.ext.typeinfo.NotFoundException;
>> >   import com.google.gwt.core.ext.typeinfo.TypeOracle;
>> >   import com.google.gwt.event.shared.HandlerManager;
>> > +import
>> com.google.gwt.requestfactory.client.impl.AbstractBooleanRequest;
>> >   import
>> com.google.gwt.requestfactory.client.impl.AbstractBigDecimalRequest;
>> >   import
>> com.google.gwt.requestfactory.client.impl.AbstractBigIntegerRequest;
>> >   import com.google.gwt.requestfactory.client.impl.AbstractByteRequest;
>> > @@ -445,6 +446,8 @@
>> >           requestClassName = AbstractDoubleRequest.class.getName();
>> >         } else if (isByteRequest(typeOracle, requestType)) {
>> >           requestClassName = AbstractByteRequest.class.getName();
>> > +      } else if (isBooleanRequest(typeOracle, requestType)) {
>> > +        requestClassName = AbstractBooleanRequest.class.getName();
>> >         } else if (isShortRequest(typeOracle, requestType)) {
>> >           requestClassName = AbstractShortRequest.class.getName();
>> >         } else if (isFloatRequest(typeOracle, requestType)) {
>> > @@ -551,6 +554,10 @@
>> >         JClassType requestType) {
>> >       return
>> >
>> requestType.isParameterized().getTypeArgs()[0].isAssignableTo(typeOracle.fi
>> ndType(BigInteger.class.getName()));
>> >     }
>> > +
>> > +  private boolean isBooleanRequest(TypeOracle typeOracle, JClassType
>> > requestType) {
>> > +    return
>> >
>> requestType.isParameterized().getTypeArgs()[0].isAssignableTo(typeOracle.fi
>> ndType(Boolean.class.getName()));
>> > +  }
>> >
>> >     private boolean isByteRequest(TypeOracle typeOracle, JClassType
>> > requestType) {
>> >       return
>> >
>> requestType.isParameterized().getTypeArgs()[0].isAssignableTo(typeOracle.fi
>> ndType(Byte.class.getName()));
>> > =======================================
>> > ---
>> >
>> /trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.j
>> ava
>> > Mon Aug  2 10:40:29 2010
>> > +++
>> >
>> /trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.j
>> ava
>> > Wed Aug  4 22:08:44 2010
>> > @@ -123,6 +123,9 @@
>> >       if (String.class == parameterType) {
>> >         return parameterValue;
>> >       }
>> > +    if (Boolean.class == parameterType || boolean.class ==
>> parameterType) {
>> > +      return Boolean.valueOf(parameterValue);
>> > +    }
>> >       if (Integer.class == parameterType || int.class == parameterType)
>> {
>> >         return new Integer(parameterValue);
>> >       }
>> > @@ -191,6 +194,9 @@
>> >         return value;
>> >       }
>> >       Class<?> type = value.getClass();
>> > +    if (Boolean.class == type) {
>> > +      return value;
>> > +    }
>> >       if (Date.class == type) {
>> >         return String.valueOf(((Date) value).getTime());
>> >       }
>> > =======================================
>> > ---
>> > /trunk/user/src/com/google/gwt/valuestore/shared/impl/RecordJsoImpl.java
>>
>> > Fri Jul 30 17:29:09 2010
>> > +++
>> > /trunk/user/src/com/google/gwt/valuestore/shared/impl/RecordJsoImpl.java
>>
>> > Wed Aug  4 22:08:44 2010
>> > @@ -83,45 +83,55 @@
>> >       // assert isDefined(property.getName()) :
>> >       // "Cannot ask for a property before setting it: "
>> >       // + property.getName();
>> > -
>> > -    if (Byte.class.equals(property.getType())) {
>> > -      return (V) Byte.valueOf((byte) getInt(property.getName()));
>> > -    }
>> > -    if (Short.class.equals(property.getType())) {
>> > -      return (V) Short.valueOf((short) getInt(property.getName()));
>> > -    }
>> > -    if (Float.class.equals(property.getType())) {
>> > -      return (V) Float.valueOf((float) getDouble(property.getName()));
>> > -    }
>> > -    if (BigInteger.class.equals(property.getType())) {
>> > -      return (V) new BigDecimal((String)
>> > get(property.getName())).toBigInteger();
>> > -    }
>> > -    if (BigDecimal.class.equals(property.getType())) {
>> > -      return (V) new BigDecimal((String) get(property.getName()));
>> > -    }
>> > -    if (Integer.class.equals(property.getType())) {
>> > -      return (V) Integer.valueOf(getInt(property.getName()));
>> > -    }
>> > -    if (Long.class.equals(property.getType())) {
>> > -      return (V) Long.valueOf((String) get(property.getName()));
>> > -    }
>> > -    if (Double.class.equals(property.getType())) {
>> > -      if (!isDefined(property.getName())) {
>> > -        return (V) new Double(0.0);
>> > -      }
>> > -      return (V) Double.valueOf(getDouble(property.getName()));
>> > -    }
>> > -    if (Date.class.equals(property.getType())) {
>> > -      double millis = new Date().getTime();
>> > -      if (isDefined(property.getName())) {
>> > -        millis = Double.parseDouble((String) get(property.getName()));
>> > -      }
>> > -      if (GWT.isScript()) {
>> > -        return (V) dateForDouble(millis);
>> > -      } else {
>> > -        // In dev mode, we're using real JRE dates
>> > -        return (V) new Date((long) millis);
>> > -      }
>> > +    if (isNull(property.getName())) {
>> > +      return null;
>> > +    }
>> > +    try {
>> > +      if (Boolean.class.equals(property.getType())) {
>> > +      return (V) Boolean.valueOf((String) get(property.getName()));
>> > +      }
>> > +      if (Byte.class.equals(property.getType())) {
>> > +        return (V) Byte.valueOf((byte) getInt(property.getName()));
>> > +      }
>> > +      if (Short.class.equals(property.getType())) {
>> > +        return (V) Short.valueOf((short) getInt(property.getName()));
>> > +      }
>> > +      if (Float.class.equals(property.getType())) {
>> > +        return (V) Float.valueOf((float)
>> getDouble(property.getName()));
>> > +      }
>> > +      if (BigInteger.class.equals(property.getType())) {
>> > +        return (V) new BigDecimal((String)
>> > get(property.getName())).toBigInteger();
>> > +      }
>> > +      if (BigDecimal.class.equals(property.getType())) {
>> > +        return (V) new BigDecimal((String) get(property.getName()));
>> > +      }
>> > +      if (Integer.class.equals(property.getType())) {
>> > +        return (V) Integer.valueOf(getInt(property.getName()));
>> > +      }
>> > +      if (Long.class.equals(property.getType())) {
>> > +        return (V) Long.valueOf((String) get(property.getName()));
>> > +      }
>> > +      if (Double.class.equals(property.getType())) {
>> > +        if (!isDefined(property.getName())) {
>> > +          return (V) new Double(0.0);
>> > +        }
>> > +        return (V) Double.valueOf(getDouble(property.getName()));
>> > +      }
>> > +      if (Date.class.equals(property.getType())) {
>> > +        double millis = new Date().getTime();
>> > +        if (isDefined(property.getName())) {
>> > +          millis = Double.parseDouble((String)
>> get(property.getName()));
>> > +        }
>> > +        if (GWT.isScript()) {
>> > +          return (V) dateForDouble(millis);
>> > +        } else {
>> > +          // In dev mode, we're using real JRE dates
>> > +          return (V) new Date((long) millis);
>> > +        }
>> > +      }
>> > +    } catch (final Exception ex) {
>> > +      throw new IllegalStateException("Property  " + property.getName()
>>
>> > + " has invalid " +
>> > +      " value " + get(property.getName()) + " for type " +
>> > property.getType());
>> >       }
>> >
>> >       if (property instanceof EnumProperty) {
>> > @@ -175,6 +185,13 @@
>> >       }
>> >       return true;
>> >     }
>> > +
>> > +  /**
>> > +   * @param name
>> > +   */
>> > +  public final native boolean isNull(String name)/*-{
>> > +    return this[name] === null;
>> > +  }-*/;
>> >
>> >     public final boolean merge(RecordJsoImpl from) {
>> >       assert getSchema() == from.getSchema();
>> > =======================================
>> > ---
>> > ...
>> >
>> > read more ยป
>>
>> --
>> http://groups.google.com/group/Google-Web-Toolkit-Contributors
>>
>
>

-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to