I want to call a validation method inside a shared gwt class that i have created to store the validation logic (for user entered text fields)
suggestBox.addKeyUpHandler( new KeyUpHandler() {
public void onKeyUp(KeyUpEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
String boxText = suggestBox.getText();
if (new FieldVerifier().validUserName(boxText)) { //inner class used to instanciate the FieldVerifier class where validUserName(String ..) lives
now i could do this with a properly instanciated FieldVerifier class (rather than a inner class as above) – or indeed, perhaps make it abstract. but i have the suspicion i am missing something (ie. must be an elegant way of doing it).
looked on google code search, but didnt come across anything particularly helpful..
If you made the
validUserName()method ofFieldVerifierstatic then you could just callFieldVerifier.validUerName()directly, without having to instantiate a FieldVerifier object. If it’s a fairly small class, though, the overhead of creating a new object is likely to be minimal.