2016-03-29 10 views
0

テキストボックスには、これは私が検証にSmartGWTの番号のみのテキストボックスを検証する方法は?

public class CreditRiskView{ 
private TextItem underlyingIDField; 
public void addunderlyingIDInputChangeHadler(ChangedHandler changedHandler) { 

    //logic is that this method will invoked in the UnderLyingIDChangeHandler class 

    underlyingIDField.addChangedHandler(changedHandler); 
    } 
public void invalidUnderlyingID(){ 

    // I don't know how to set an error message as underlyingIDField.clearValue() 
     method is not doing well. 

    } 
} 
を表示する必要がメインクラスです

public class UnderLyingIDChangeHandler implements ChangedHandler { 
    private final CreditRiskView creditRiskView; 

    public UnderLyingIDChangeHandler(CreditRiskView creditRiskView) { 
     this.creditRiskView = creditRiskView; 
    } 
    @Override 
    public void onChanged(ChangedEvent event) { 
     String value= (String) event.getItem().getValue(); 
     if(!value.matches("[0-9]*")){ 
      creditRiskView.invalidUnderlyingID(); 
     } 
} 

、私はChangedHandler/ Changehandler/ KeyPressHandler

私のバリデーションクラス以外の他の任意のハンドラを使用したい、数字だけを受け入れる必要があります

答えて

2

: は、このサンプルを参照してください

IsIntegerValidator isIntegerValidator = new IsIntegerValidator(); 
isIntegerValidator.setErrorMessage("error message"); 
textItem.setValidators(isIntegerValidator); 

そして、あなたはフォームを呼び出すときにそのようなエラーを表示します.validate()setShowInlineErrors(true)をフォームに設定する必要があります。

+0

..感謝 – Joseph

0

ユーザーが入力できる文字の制限はどうですか?テキストボックスは、DynamicFormTextItemであれば、それはこのように動作します http://www.smartclient.com/smartgwt/showcase/#form_keypress_filter

+0

ですが、ユーザーは任意の値を入力でき、[link](https://www.google.co.in/search?q=validation+example+images&espv=2&biw=)のような例を検証する必要があります。 25252F%25252F%25252F18%25252F18%25252F18%-25%25252F18%25252F18%25252F18%25252F18%-25%-25% M&モミ= 5-NnMuVG8GyU-Mの%253A%252CwYih5EUmz9nrkM%252C_&USG = __ msnZlG6RD45XOPMEIe9Kq9WkLuI%3D&VED = 0ahUKEwij5_fYhejLAhUPco4KHZ7rA9AQyjcILg&EI = UJX7VqP_J4_kuQSe14-ADQ#1 imgrc = 5-NnMuVG8GyU-M%の3A)これは:)正常に動作します – Joseph

関連する問題