Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

TextItem.getValueAsString() occasionally returning asterisks

$
0
0
SmartGwtVersion: 2.5
GwtVersion: 2.3.0

Issue description:
We are running into this strange issue, where sometimes TextItem.getValueAsString() method returns asterisks ("*"). Please note, this only happening in Production server on few occassions, and not reproducible in our QA environment.
We have captured the user's browser details in 2 occassions :
1. Firefox 29, Windows 8, , Personal Computer
2. Safari 7.0.4, OS X 10.9 Mavericks, Personal Computer

As this is not re-producible locally, we would appreciate any help on this. Below is the code for affected TextItem field, where form is populated with existing value using setTextItemValue() method, prior to edit.

Please let us know if you need any more information on this.

Code:

public class MyDynamicForm extends DynamicForm {
    public TextItem textItem;
       
    public MyDynamicForm() {
                textItem = new TextItem("textItem", "textItem");
                textItem.setKeyPressFilter("[a-zA-Z0-9]");
                textItem.addChangeHandler(getInvalidCharacterChangeHandler());
        }
       
        public String getTextItemValue() {
              return textItem.getValue() == null ? "" : textItem.getValueAsString();
        }

            public void setTextItemValue(String textValue) {
              textItem.setValue(textValue);
        }
       
    /* Disallow entering or pasting invalid characters.
    *
    */
    private ChangeHandler getInvalidCharacterChangeHandler() {
        return new ChangeHandler() {
            @Override
            public void onChange(ChangeEvent changeEvent) {
                if (changeEvent.getValue() == null) {
                    return;
                }
                TextItem item = (TextItem) changeEvent.getItem();
                String keyPressFilter = item.getKeyPressFilter();
                RegExp regExp = RegExp.compile(keyPressFilter, "g");
                List<String> matches = getMatches((String) changeEvent.getValue(), regExp);
                String filtered = "";
                for (String match : matches) {
                    filtered += match;
                }
                if (!filtered.equals(changeEvent.getValue())) {
                    item.setValue(filtered);
                    changeEvent.cancel();
                }
            }           
        };
    }

    private List<String> getMatches(String input, RegExp regExp) {
        ArrayList<String> matches = new ArrayList<String>();
        for (MatchResult matcher = regExp.exec(input); matcher != null; matcher = regExp.exec(input)) {
            matches.add(matcher.getGroup(0));
        }
        return matches;
    }       
}


Viewing all articles
Browse latest Browse all 4756

Trending Articles