フィールドに Apache Struts 用のバリデーションメソッドを自動生成します。
要素名 | 型 | デフォルト | 説明 |
- package sample.struts;
- import org.apache.struts.action.ActionForm;
- import blanco.gettersetter.BlancoGetterSetter;
- import blanco.struts.BlancoStrutsForm;
- import blanco.struts.BlancoStrutsReset;
- import blanco.validate.BlancoValidateLength;
- import blanco.validate.BlancoValidateMethodForStruts;
- import blanco.validate.BlancoValidateRequired;
- /**
- * サンプル・フォーム。
- */
- @BlancoStrutsForm
- public abstract class AbstractSampleForm extends ActionForm {
- private static final long serialVersionUID = 1L;
- /**
- * 文字列のフィールド。
- */
- @BlancoGetterSetter
- @BlancoStrutsReset
- @BlancoValidateMethodForStruts
- @BlancoValidateRequired
- @BlancoValidateLength(max = 5)
- protected String field1 = "";
- /**
- * 整数のフィールド。
- */
- @BlancoGetterSetter
- protected int field2 = -1;
- }
- /*
- * このクラスは 'AbstractSampleForm' の具象クラスとして blanco Framework によって自動生成されました。
- */
- package sample.struts;
- import javax.servlet.http.HttpServletRequest;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.action.ActionMessage;
- import org.apache.struts.action.ActionMessages;
- import blanco.fw.BlancoGeneratedBy;
- /**
- * サンプル・フォーム。
- */
- @BlancoGeneratedBy(name = "Blanco2g")
- public class SampleForm extends AbstractSampleForm {
- /**
- * シリアルバージョン UID.
- */
- private static final long serialVersionUID = 1L;
- /**
- * リセット
- *
- * @param mapping アクション・マッピング.
- * @param request リクエスト.
- */
- public void reset(final ActionMapping mapping, final HttpServletRequest request) {
- field1 = "";
- }
- /**
- * 文字列のフィールド。
- * [@BlancoGetterSetter]
- *
- * @return 取得したい値。
- */
- public String getField1() {
- return field1;
- }
- /**
- * 文字列のフィールド。
- * [@BlancoGetterSetter]
- *
- * @param field1 設定したい値。
- */
- public void setField1(final String field1) {
- this.field1 = field1;
- }
- /**
- * 文字列のフィールド。
- * [@BlancoValidateRequired]
- * [@BlancoValidateLength]
- *
- * @return 検証結果の文字列。問題なければ null。
- */
- public String validateField1() {
- // [@BlancoValidateRequired]
- if (field1 == null || field1.trim().length() == 0) {
- return "'field1' に値が入力されていません。";
- }
- // [@BlancoValidateLength]
- {
- final String value = (field1 == null ? "" : field1.toString());
- if (value.length() > 5) {
- return "'field1' は 5 文字以下で入力してください。";
- }
- }
- return null;
- }
- /**
- * 文字列のフィールド。
- * [@BlancoValidateMethodForStruts]
- * [@BlancoValidateLength]
- *
- * @param actionMessages Apache Struts ActionMessages
- * @return 検証結果が問題無しであれば true。検証結果に問題あれば false。
- */
- public boolean validateField1(final ActionMessages actionMessages) {
- // [@BlancoValidateRequired]
- if (field1 == null || field1.trim().length() == 0) {
- final ActionMessage msg = new ActionMessage("message.blanco.validate.required.input", "field1");
- actionMessages.add("WARN", msg);
- return false;
- }
- // [@BlancoValidateLength]
- {
- final String value = (field1 == null ? "" : field1.toString());
- if (value.length() > 5) {
- final ActionMessage msg = new ActionMessage("message.blanco.validate.length.max", "field1", "5");
- actionMessages.add("WARN", msg);
- return false;
- }
- }
- return true;
- }
- /**
- * 整数のフィールド。
- * [@BlancoGetterSetter]
- *
- * @return 取得したい値。
- */
- public int getField2() {
- return field2;
- }
- /**
- * 整数のフィールド。
- * [@BlancoGetterSetter]
- *
- * @param field2 設定したい値。
- */
- public void setField2(final int field2) {
- this.field2 = field2;
- }
- }