Browse Source

Revert "Better default for nullRepresentation (#13221, #12877)"

This reverts commit 85870ccd9f.

Change-Id: Ifb9bbac0ee36e71d2251c31b936a12f1f3ea7315
tags/7.7.0.alpha2
Ilia Motornyi 8 years ago
parent
commit
ef306c16f5

+ 0
- 12
server/src/main/java/com/vaadin/server/DefaultDeploymentConfiguration.java View File

@@ -21,7 +21,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;

import com.vaadin.shared.communication.PushMode;
import com.vaadin.ui.AbstractTextField;

/**
* The default implementation of {@link DeploymentConfiguration} based on a base
@@ -98,17 +97,6 @@ public class DefaultDeploymentConfiguration extends
checkLegacyPropertyToString();
checkSyncIdCheck();
checkSendUrlsAsParameters();
checkNullRepresentationLegacyMode();
}

private void checkNullRepresentationLegacyMode() {
final boolean legacyMode = getApplicationOrSystemProperty(
"com.vaadin.nullrepresentationlegacymode",
Boolean.toString(false)).equals("true");
if (legacyMode) {
AbstractTextField.setNullRepresentationDefault("null");
}

}

private void checkLegacyPropertyToString() {

+ 1
- 36
server/src/main/java/com/vaadin/ui/AbstractTextField.java View File

@@ -41,13 +41,10 @@ import com.vaadin.ui.declarative.DesignContext;
public abstract class AbstractTextField extends AbstractField<String> implements
BlurNotifier, FocusNotifier, TextChangeNotifier, LegacyComponent {

private static String nullRepresentationDefault = "";

/**
* Null representation.
*/
private String nullRepresentation = nullRepresentationDefault;

private String nullRepresentation = "null";
/**
* Is setting to null from non-null value allowed by setting with null
* representation .
@@ -813,36 +810,4 @@ public abstract class AbstractTextField extends AbstractField<String> implements
getMaxLength(), def.getMaxLength(), Integer.class);
}

/**
* @since 7.6
* @return the default value used for nullRepresentation
*/
public static String getNullRepresentationDefault() {
return nullRepresentationDefault;
}

/**
* A static helper to define the default value used for nullRepresentation.
* <p>
* In 7.6 the infamous default value "null" for
* AbstractTextField.nullRepresentation was changed to "", which may cause
* unexpected issues in certain applications that don't tackle null values.
* If there are several places in your application that depend on the old
* default, this method can be used to put new AbstractTextField instances
* into backwards compatibility mode by defining the default value as
* "null". The "legacy mode" can also be forced by setting system property
* "com.vaadin.nullrepresentationlegacymode" (before AbstractTextField class
* is loaded by your class loader).
*
* @since 7.6
* @param nullRepresentationString
* the value that will be used as a default for
* {@link AbstractTextField#getNullRepresentation()} in new
* instances
*/
public static void setNullRepresentationDefault(
String nullRepresentationString) {
AbstractTextField.nullRepresentationDefault = nullRepresentationString;
}

}

+ 0
- 84
uitest/src/main/java/com/vaadin/tests/components/textfield/NullRepresentationLegacyMode.java View File

@@ -1,84 +0,0 @@
/*
* Copyright 2000-2014 Vaadin Ltd.
*
* 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.vaadin.tests.components.textfield;

import com.vaadin.annotations.Theme;
import com.vaadin.data.fieldgroup.BeanFieldGroup;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.AbstractTextField;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings("serial")
@Theme("valo")
public class NullRepresentationLegacyMode extends AbstractTestUI {

public static class Entity {

private String value;

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

}

public static class Form extends VerticalLayout {
TextField value = new TextField();

public Form() {
setMargin(true);
setSpacing(true);
addComponent(value);
}
}

@Override
protected void setup(VaadinRequest request) {
Form formWithoutNulls = new Form();
formWithoutNulls.setCaption("No 'null's here please");
formWithoutNulls.setId("without");
BeanFieldGroup.bindFieldsUnbuffered(new Entity(), formWithoutNulls);

// Use the legacy default
AbstractTextField.setNullRepresentationDefault("null");

Form formWithNulls = new Form();
formWithNulls.setCaption("'null's please");
formWithNulls.setId("with");
BeanFieldGroup.bindFieldsUnbuffered(new Entity(), formWithNulls);
AbstractTextField.setNullRepresentationDefault("");

addComponents(formWithoutNulls, formWithNulls);
}

@Override
protected String getTestDescription() {
return "Text field must not truncate underscores in modal dialogs.";
}

@Override
protected Integer getTicketNumber() {
return 12974;
}

}

+ 1
- 9
uitest/src/main/java/com/vaadin/tests/fieldgroup/MultipleValidationErrors.java View File

@@ -1,7 +1,5 @@
package com.vaadin.tests.fieldgroup;

import org.apache.commons.lang.StringEscapeUtils;

import com.vaadin.data.Validator;
import com.vaadin.data.fieldgroup.FieldGroup;
import com.vaadin.data.util.BeanItem;
@@ -9,10 +7,10 @@ import com.vaadin.data.validator.BeanValidator;
import com.vaadin.server.AbstractErrorMessage;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.AbstractTextField;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import org.apache.commons.lang.StringEscapeUtils;

public class MultipleValidationErrors extends AbstractTestUI {

@@ -27,15 +25,9 @@ public class MultipleValidationErrors extends AbstractTestUI {
new PersonBeanWithValidationAnnotations());
final FieldGroup fieldGroup = new FieldGroup(item);

// use old default that this test depends on
AbstractTextField.setNullRepresentationDefault("null");

bindTextField(item, fieldGroup, "First Name", "firstName");
bindTextField(item, fieldGroup, "Last Name", "lastName");

// Revert to new
AbstractTextField.setNullRepresentationDefault("");

final Label validationErrors = new Label();
validationErrors.setId("validationErrors");
addComponent(validationErrors);

+ 0
- 21
uitest/src/test/java/com/vaadin/tests/components/textfield/NullRepresentationLegacyModeTest.java View File

@@ -1,21 +0,0 @@
package com.vaadin.tests.components.textfield;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;

import com.vaadin.tests.tb3.MultiBrowserTest;

public class NullRepresentationLegacyModeTest extends MultiBrowserTest {

@Test
public void testWindowRepositioning() throws Exception {
openTestURL();
String without = getDriver().findElement(
By.xpath("//div[@id='without']//input")).getAttribute("value");
String with = getDriver().findElement(
By.xpath("//div[@id='with']//input")).getAttribute("value");
Assert.assertEquals("null", with);
Assert.assertEquals("", without);
}
}

Loading…
Cancel
Save