範囲チェックについて

WicketRangeCheck.png

値の範囲チェック

入力項目チェック仕様TextField?への追記法備考
整数より大きいTextField?.add(new NumberValidator?.MinimumValidator?( min ))minを含む
TextField?.add(NumberValidator?.minimum( min ))内部的に new MinimumValidatior?(min) している
より小さいTextField?.add(new NumberValidator?.MaximumValidator?( max ))maxを含む
TextField?.add(NumberValidator?.maximum( min ))内部的に new MaximumValidatior?(max) している
の範囲内TextField?.add(new NumberValidator?.RangeValidator?( min, max ))min,maxを含む
TextField?.add(NumberValidator?.range( min, max ))内部的に new RangeValidator?(min,max) している
浮動小数より大きいTextField?.add(new NumberValidator?.DoubleMinimumValidator?( min ))minを含む
TextField?.add(NumberValidator?.minimum( min ))内部的に new DoubleMinimumValidatior?(min) している
より小さいTextField?.add(new NumberValidator?.DoubleMinimumValidator?( max ))maxを含む
TextField?.add(NumberValidator?.maximum( min ))内部的に new DoubleMaximumValidatior?(max) している
の範囲内TextField?.add(new NumberValidator?.DoubleRangeValidator?( min, max ))min,maxを含む
TextField?.add(NumberValidator?.range( min, max ))内部的に new DoubleRangeValidator?(min,max) している
整数・浮動小数正の数TextField?.add(NumberValidator?.POSITIVE)内部的に new MinimumValidatior?(Float.MIN_VALUE) している
負の数TextField?.add(NumberValidator?.NEGATIVE)内部的に new MinimumValidatior?(-1.0*Float.MIN_VALUE) している

文字列の範囲チェック

入力項目チェック仕様TextField?への追記法備考
文字列より長いTextField?.add(new StringValidator?.MinimumLengthValidator?( min ))minを含む
TextField?.add(StringValidator?.minimumLength( min ))内部的に new MinimumValidatior?(min) している
より短いTextField?.add(new StringValidator?.MaximumLengthValidator?( max ))maxを含む
TextField?.add(StringValidator?.maximumLenght( min ))内部的に new MaximuLengthmValidatior?(max) している
の範囲内TextField?.add(new StringValidator?.LengthBetweenValidator?( min, max ))min,maxを含む
TextField?.add(StringValidator?.lengthBetween( min, max ))内部的に new LengthBetweenValidator?(min,max) している
N文字TextField?.add(new StringValidator?.ExactLengthValidator?( exact ))examct文字でなければならない
TextField?.add(StringValidator?.exactLength( exact ))内部的に new ExactLengthValidator?(exact) している

※半角全角の区別無し、"A" も "愛" も 1文字として扱われる。
※サロゲート文字は 2文字として扱われる。

日付の範囲チェック

入力項目チェック仕様TextField?への追記法備考
日付より後TextField?.add(DateValidator?.minimum( min ))内部的に new MinimumValidatior?(min) している※
より前TextField?.add(DateValidator?.maximum( max ))内部的に new MinimumValidatior?(min) している※
の範囲内TextField?.add(DateValidator?.range( min, max ))内部的に new RangeValidatior?(min,max) している※

DateValidator?.???Validator は、Private Class なので、外部から直接インスタンス化できない。
けど、エラーメッセージを変えたいとき(${画面名}.propertiesをいじるとき)には、どのValidation クラスを使っているのかを意識する必要がある [oh]

RangeCheckExamPage?.html

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:wicket="http://wicket.apache.org/">
<head>
<title>Wicket Range Check Examination Page</title>
</head>
<body>
<strong>Wicket Range Check Examination Page</strong>
<p align="right"><a wicket:id="back">back to menu</a></p>
<span wicket:id="msg"> error message will be here </span>
<form wicket:id="f">
	<fieldset>
		<legend>Numeric Check</legend>
		<table border="0">
			<tr>
				<td>Minimum Value Check</td><td>:</td>
				<td><input type="text" wicket:id="int1" size="20" /></td>
				<td>Greater Equal Than <span wicket:id="int1Min">XX</span></td>
			</tr>
			<tr>
				<td>Maximum Value Check</td><td>:</td>
				<td><input type="text" wicket:id="int2" size="20" /></td>
				<td>Less Equal Than <span wicket:id="int2Max">XX</span></td>
			</tr>
			<tr>
				<td>Range Value Check</td><td>:</td>
				<td><input type="text" wicket:id="int3" size="20" /></td>
				<td>(<span wicket:id="int3Min">XX</span>〜<span wicket:id="int3Max">YY</span>)</td>
			</tr>
			<tr>
				<td>Positive Value Check</td><td>:</td>
				<td><input type="text" wicket:id="int4" size="20" /></td>
				<td>Positive Value</td>
			</tr>
			<tr>
				<td>Negative Value Check</td><td>:</td>
				<td><input type="text" wicket:id="int5" size="20" /></td>
				<td>Negative Value</td>
			</tr>
		</table>
	</fieldset>
	<fieldset>
		<legend>String Length Check</legend>
		<table border="0">
			<tr>
				<td>Minimum Length Check</td><td>:</td>
				<td><input type="text" wicket:id="str1" size="20" /></td>
				<td>Greater Equal Than <span wicket:id="str1Min">XX</span> characters</td>
			</tr>
			<tr>
				<td>Maximum Check</td><td>:</td>
				<td><input type="text" wicket:id="str2" size="20" /></td>
				<td>Less Equal Than <span wicket:id="str2Max">XX</span> characters</td>
			</tr>
			<tr>
				<td>Range Check</td><td>:</td>
				<td><input type="text" wicket:id="str3" size="20" /></td>
				<td>(<span wicket:id="str3Min">XX</span>〜<span wicket:id="str3Max">YY</span>) characters</td>
			</tr>
			<tr>
				<td>Exact Check</td><td>:</td>
				<td><input type="text" wicket:id="str4" size="20" /></td>
				<td>Exact <span wicket:id="str4Exact">XX</span> characters</td>
			</tr>
		</table>
	</fieldset>
	<fieldset>
		<legend>Date Check</legend>
		<table border="0">
			<tr>
				<td>Minimum Date Check</td><td>:</td>
				<td><input type="text" wicket:id="date1" size="20" /></td>
				<td>Greater Equal Than <span wicket:id="date1Min">XX</span></td>
			</tr>
			<tr>
				<td>Maximum Date Check</td><td>:</td>
				<td><input type="text" wicket:id="date2" size="20" /></td>
				<td>Less Equal Than <span wicket:id="date2Max">XX</span></td>
			</tr>
			<tr>
				<td>Range Date Check</td><td>:</td>
				<td><input type="text" wicket:id="date3" size="20" /></td>
				<td>(<span wicket:id="date3Min">XX</span>〜<span wicket:id="date3Max">YY</span>)</td>
			</tr>
		</table>
	</fieldset>
	<input type="submit" value="POST" />
</form>
</body>
</html>

RangeCheckExamVo?.java

package com.snail.wicket.exam.validation;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class RangeCheckExamVo implements Serializable {
  private static final long serialVersionUID = 7107977074548851486L;

  public static final String INT1 = "int1";
  public static final String INT2 = "int2";
  public static final String INT3 = "int3";
  public static final String INT4 = "int4";
  public static final String INT5 = "int5";
  
  public static final String STR1 = "str1";
  public static final String STR2 = "str2";
  public static final String STR3 = "str3";
  public static final String STR4 = "str4";
  
  public static final String DATE1 = "date1";
  public static final String DATE2 = "date2";
  public static final String DATE3 = "date3";
  
  public static final int INT1_MIN = 3;
  public static final int INT2_MAX = 5;
  public static final int INT3_MIN = 2;
  public static final int INT3_MAX = 10;
  
  public static final int STR1_MIN = 3;
  public static final int STR2_MAX = 5;
  public static final int STR3_MIN = 2;
  public static final int STR3_MAX = 10;
  public static final int STR4_LENGTH = 5;

  public static Date DATE1_MIN;
  public static Date DATE2_MAX;
  public static Date DATE3_MIN;
  public static Date DATE3_MAX;
  
  // 入力項目の初期値は、View (WebPageクラス) ではなく、Model (VOクラス) に有るべきだろう
  static{
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    try {
      DATE1_MIN = df.parse("1970-1-1");
      DATE2_MAX = df.parse("2049-12-31");
      DATE3_MIN = df.parse("2000-1-1");
      DATE3_MAX = df.parse("2999-12-31");
    } catch (ParseException e) {
      e.printStackTrace();
    }
  }
  
  private int int1;
  private int int2;
  private int int3;
  private int int4;
  private int int5;
  
  private String str1;
  private String str2;
  private String str3;
  private String str4;
  
  private Date date1;
  private Date date2;
  private Date date3;
  
  public Date getDate1() {
    return date1;
  }
  public void setDate1(Date date1) {
    this.date1 = date1;
  }
  public Date getDate2() {
    return date2;
  }
  public void setDate2(Date date2) {
    this.date2 = date2;
  }
  public Date getDate3() {
    return date3;
  }
  public void setDate3(Date date3) {
    this.date3 = date3;
  }
  public int getInt1() {
    return int1;
  }
  public void setInt1(int int1) {
    this.int1 = int1;
  }
  public int getInt2() {
    return int2;
  }
  public void setInt2(int int2) {
    this.int2 = int2;
  }
  public int getInt3() {
    return int3;
  }
  public void setInt3(int int3) {
    this.int3 = int3;
  }
  public int getInt4() {
    return int4;
  }
  public void setInt4(int int4) {
    this.int4 = int4;
  }
  public int getInt5() {
    return int5;
  }
  public void setInt5(int int5) {
    this.int5 = int5;
  }
  public String getStr1() {
    return str1;
  }
  public void setStr1(String str1) {
    this.str1 = str1;
  }
  public String getStr2() {
    return str2;
  }
  public void setStr2(String str2) {
    this.str2 = str2;
  }
  public String getStr3() {
    return str3;
  }
  public void setStr3(String str3) {
    this.str3 = str3;
  }
  public String getStr4() {
    return str4;
  }
  public void setStr4(String str4) {
    this.str4 = str4;
  }
}

RangeCheckExamPage?.java

package com.snail.wicket.exam.validation;

import org.apache.wicket.extensions.markup.html.form.DateTextField;
import org.apache.wicket.extensions.yui.calendar.DatePicker;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.validation.validator.DateValidator;
import org.apache.wicket.validation.validator.NumberValidator;
import org.apache.wicket.validation.validator.StringValidator;

import com.snail.wicket.exam.MenuPage;

public class RangeCheckExamPage extends WebPage {
  private static final long serialVersionUID = 3914250268292061821L;

  private FeedbackPanel feedback = new FeedbackPanel("msg");

  private RangeCheckExamVo vo = new RangeCheckExamVo();

  private Form form = new Form("f", new CompoundPropertyModel(vo));

  private Link backLink = new Link("back") {
    private static final long serialVersionUID = 6481057398828649660L;

      @Override
      public void onClick() {
        setResponsePage(new MenuPage());
      }
    };

  private TextField int1TextField = new TextField(RangeCheckExamVo.INT1);
  private TextField int2TextField = new TextField(RangeCheckExamVo.INT2);
  private TextField int3TextField = new TextField(RangeCheckExamVo.INT3);
  private TextField int4TextField = new TextField(RangeCheckExamVo.INT4);
  private TextField int5TextField = new TextField(RangeCheckExamVo.INT5);

  private TextField str1TextField = new TextField(RangeCheckExamVo.STR1);
  private TextField str2TextField = new TextField(RangeCheckExamVo.STR2);
  private TextField str3TextField = new TextField(RangeCheckExamVo.STR3);
  private TextField str4TextField = new TextField(RangeCheckExamVo.STR4);

  private DateTextField date1TextField = new DateTextField(RangeCheckExamVo.DATE1,"yyyy年MM月dd日");
  private DateTextField date2TextField = new DateTextField(RangeCheckExamVo.DATE2,"yyyy年MM月dd日");
  private DateTextField date3TextField = new DateTextField(RangeCheckExamVo.DATE3,"yyyy年MM月dd日");

  public RangeCheckExamPage() {
    add(form);
    add(feedback);
    add(backLink);
    int1TextField.setRequired(true);
    int1TextField.add(new NumberValidator.MinimumValidator(
        RangeCheckExamVo.INT1_MIN));
    form.add(int1TextField);
    form.add(new Label(RangeCheckExamVo.INT1 + "Min",
        Integer.toString(RangeCheckExamVo.INT1_MIN)));

    int2TextField.setRequired(true);
    int2TextField.add(new NumberValidator.MaximumValidator(
        RangeCheckExamVo.INT2_MAX));
    form.add(int2TextField);
    form.add(new Label(RangeCheckExamVo.INT2 + "Max",
        Integer.toString(RangeCheckExamVo.INT2_MAX)));

    int3TextField.setRequired(true);
    int3TextField.add(new NumberValidator.RangeValidator(
        RangeCheckExamVo.INT3_MIN, RangeCheckExamVo.INT3_MAX));
    form.add(int3TextField);
    form.add(new Label(RangeCheckExamVo.INT3 + "Min",
        Integer.toString(RangeCheckExamVo.INT3_MIN)));
    form.add(new Label(RangeCheckExamVo.INT3 + "Max",
        Integer.toString(RangeCheckExamVo.INT3_MAX)));

    int4TextField.setRequired(true);
    int4TextField.add(NumberValidator.POSITIVE);
    form.add(int4TextField);

    int5TextField.setRequired(true);
    int5TextField.add(NumberValidator.NEGATIVE);
    form.add(int5TextField);
    
    str1TextField.add(new StringValidator.MinimumLengthValidator(
        RangeCheckExamVo.STR1_MIN));
    form.add(str1TextField);
    form.add(new Label(RangeCheckExamVo.STR1 + "Min",
        Integer.toString(RangeCheckExamVo.STR1_MIN)));

    str2TextField.add(new StringValidator.MaximumLengthValidator(
        RangeCheckExamVo.STR2_MAX));
    form.add(str2TextField);
    form.add(new Label(RangeCheckExamVo.STR2 + "Max",
        Integer.toString(RangeCheckExamVo.STR2_MAX)));

    str3TextField.add(new StringValidator.LengthBetweenValidator(
        RangeCheckExamVo.STR3_MIN, RangeCheckExamVo.STR3_MAX));
    form.add(str3TextField);
    form.add(new Label(RangeCheckExamVo.STR3 + "Min",
        Integer.toString(RangeCheckExamVo.STR3_MIN)));
    form.add(new Label(RangeCheckExamVo.STR3 + "Max",
        Integer.toString(RangeCheckExamVo.STR3_MAX)));
    
    str4TextField.add(new StringValidator.ExactLengthValidator(
        RangeCheckExamVo.STR4_LENGTH));
    form.add(str4TextField);
    form.add(new Label(RangeCheckExamVo.STR4 + "Exact",
        Integer.toString(RangeCheckExamVo.STR4_LENGTH)));

    date1TextField.add(DateValidator.minimum(RangeCheckExamVo.DATE1_MIN));
    date1TextField.add(new DatePicker());
    form.add(date1TextField);
    form.add(new Label(RangeCheckExamVo.DATE1 + "Min",
        RangeCheckExamVo.DATE1_MIN.toString()));
    
    date2TextField.add(DateValidator.maximum(RangeCheckExamVo.DATE2_MAX));
    date2TextField.add(new DatePicker());
    form.add(date2TextField);
    form.add(new Label(RangeCheckExamVo.DATE2 + "Max",
        RangeCheckExamVo.DATE2_MAX.toString()));

    date3TextField.add(DateValidator.range(RangeCheckExamVo.DATE3_MIN,RangeCheckExamVo.DATE3_MAX));
    date3TextField.add(new DatePicker());
    form.add(date3TextField);
    form.add(new Label(RangeCheckExamVo.DATE3 + "Min",
        RangeCheckExamVo.DATE3_MIN.toString()));
    form.add(new Label(RangeCheckExamVo.DATE3 + "Max",
        RangeCheckExamVo.DATE3_MAX.toString()));
  }
}

Java


添付ファイル: fileWicketRangeCheck.png 773件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS   sitemap
Last-modified: 2008-02-18 (月) 01:42:54 (3213d)
ISBN10
ISBN13
9784061426061