2012-02-22 5 views
0

Jsp(struts2アプリケーション)のfromDateとtoDateに次のコードを使用しています。struts2でfromDate、toDateを<sx:datetimepicker>を使用して検証する方法は?

<s:label value="valid From* "/> 
<sx:datetimepicker required="true" name="validFrom" displayFormat="dd/MM/yyyy" /> 
<s:label value="Valid To * :" /> 
<sx:datetimepicker required="true" name="validTo" displayFormat="dd/MM/yyyy" /> 

指定された形式の日付が生成されています。選択した日付の値をチェックしたい場合、TodateがFromdateより小さい場合はエラーメッセージを表示する必要があります。

誰でもこの問題を解決するのに役立ちますか?前もって感謝します。

答えて

0

おそらく最も単純な方法は、おそらくActionSupportを拡張することで最も簡単なValidateableを実装することです。注意 "validFrom"を単に "from"と "validTo"を単に "to"に変更しました。

次に、あなたの行動にあなたが書くでしょう...

//Not tested 
public void Validate(){ 
    //it is obvious that if one of these conditions is true the other will be as well 
    //this is just to show the typical case of building up multiple field errors 
    if (to.before(from)){ 
     addFieldError("to", getText("To date must be later than from date.")); 
    } 
    if (from.after(to)){ 
     addFieldError("from", getText("From date must be before to date.")); 
    } 
} 

私はあなたがより細かく制御したい場合には、あなたがhttp://struts.apache.org/2.2.1.1/docs/fielderror.htmlとフィールドエラーを取得することができます見つけることができますシンプルなテーマを選ぶのが好きので、エラーメッセージが表示されます。

詳細については、http://struts.apache.org/2.x/docs/validation.html

をご覧ください。
関連する問題