はじめに

WicketValidation.png

ValidationExamPage?.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 Validation Examination Homepage</title>
</head>
<body>
<strong>Wicket Validation Examination Homepage</strong>
<br />
<br />
<span wicket:id="msg"> error message will be here </span>
<form wicket:id="f">
	Start : <input type="text" wicket:id="start" size="20" />
	End : <input type="text" wicket:id="end" size="20" /> <br />
	<input type="submit" value="POST" />
</form>
</body>
</html>

ValidationExamVo?.java

package com.snail;

import java.io.Serializable;
import java.util.Date;

public class ValidationExamVo implements Serializable{
  private static final long serialVersionUID = 8118905069882346381L;
  public static final String START = "start";
  public static final String END = "end";
  private Date start;
  private Date end;
  public Date getStart() {
    return start;
  }
  public void setStart(Date start) {
    this.start = start;
  }
  public Date getEnd() {
    return end;
  }
  public void setEnd(Date end) {
    this.end = end;
  }
}

ValidationExamPage?.java

package com.snail;

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.form.Form;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;

public class ValidationExamPage extends WebPage {
  private static final long serialVersionUID = 5261959667681075067L;

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

  private ValidationExamVo vo = new ValidationExamVo();

  private Form form = new Form("f", new CompoundPropertyModel(vo)) {
      private static final long serialVersionUID = 8219220062798577531L;

      @Override
      protected void onSubmit() {
        if(vo.getStart().after(vo.getEnd())){
          error("Startは、Endよりも前です");
        }
      }
    };

  public ValidationExamPage() {
    add(form);
    add(feedback);

    DateTextField start = new DateTextField(ValidationExamVo.START);
    start.setRequired(true);
    start.add(new DatePicker());
    form.add(start);

    DateTextField end = new DateTextField(ValidationExamVo.END);
    end.setRequired(true);
    end.add(new DatePicker());
    form.add(end);
  }
}

Place Holder の利用

入力検証エラーの発生元をはっきりさせたい

Date型として適切でないものが入力されても大丈夫


Java#Wicket


添付ファイル: fileWicketValidator.png 1220件 [詳細] fileWicketValidation3.png 2406件 [詳細] fileWicketValidation2.png 2384件 [詳細] fileWicketValidation.png 2530件 [詳細] fileWicketValidation4.png 2405件 [詳細] fileWicketHomePageProperties.png 1266件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS   sitemap
Last-modified: 2008-02-15 (金) 02:46:25 (6084d)
Short-URL: http://at-sushi.com/pukiwiki/index.php?cmd=s&k=60838ee0c7
ISBN10
ISBN13
9784061426061