質問編集履歴

1

ソースを追記

2022/09/29 01:35

投稿

takuson
takuson

スコア36

test CHANGED
File without changes
test CHANGED
@@ -8,10 +8,105 @@
8
8
  struts-validationを使用して、ボタンによる入力項目のチェック制御を行いたい
9
9
 
10
10
  ### 試したこと
11
+ 画面の入力項目すべてに対してvalidationでチェックが行われることは確認済み
12
+ #### ソース
13
+ ```sample.jsp
14
+ <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
15
+ <%@ page language="java" %>
16
+ <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
17
+ <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
11
18
 
19
+ <html:html>
20
+ <head>
21
+ <title>入力フォーム</title>
22
+ </head>
23
+ <body>
24
+ <html:form action="sampleAction">
25
+ <html:errors/>
26
+ <html:text property="input1" size="10" maxlength="7"/>
27
+ <html:submit property="submut1" value="送信" />
28
+ <br>
29
+ <html:text property="input2" size="10" maxlength="7"/>
30
+ <html:submit property="submut2" value="送信" />
31
+ </html:form>
32
+ </body>
33
+ </html:html>
34
+ ```
35
+ ```validation.xml
36
+ <?xml version="1.0" encoding="UTF-8"?>
37
+ <!DOCTYPE form-validation PUBLIC
38
+ "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN"
39
+ "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">
40
+ <form-validation>
41
+ <formset>
42
+ <form name="SampleForm">
43
+ <field property="input1" depends="integer">
44
+ <arg key="入力欄1" resource="false"/>
45
+ </field>
46
+ <field property="input2" depends="integer">
47
+ <arg key="入力欄2" resource="false"/>
48
+ </field>
49
+ </form>
50
+ </formset>
12
- 画面の入力項目すべてに対してvalidationでチェックが行われることは確認済み
51
+ </form-validation>
52
+ ```
53
+ ```struts_config.xml
54
+ <?xml version="1.0" encoding="UTF-8"?>
55
+ <!DOCTYPE struts-config PUBLIC
56
+ "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
57
+ "http://struts.apache.org/dtds/struts-config_1_2.dtd">
13
58
 
59
+ <struts-config>
14
60
 
61
+ <form-beans>
62
+ <form-bean name="SZ01S001Form" type="sample.SZ01S001Form"/>
63
+ <form-bean name="SampleForm" type="sample.SampleForm"/>
64
+ </form-beans>
65
+
66
+ <global-exceptions/>
67
+ <global-forwards/>
68
+
69
+ <action-mappings>
70
+
71
+ <action name="SampleForm"
72
+ path="/sampleAction" scope="request"
73
+ type="sample.loginAction"
74
+ input="/jsp/sample.jsp"
75
+ validate="true">
76
+ <forward name="homeAction" path="/jsp/home.jsp"/>
77
+ </action>
78
+ </action-mappings>
79
+
80
+ </struts-config>
81
+
82
+ ```
83
+ ```sampleForm.java
84
+ package sample;
85
+
86
+ public class SampleForm {
87
+ private String input1;
88
+
89
+ private String input2;
90
+
91
+ public String getInput1() {
92
+ return input1;
93
+ }
94
+
95
+ public void setInput1(String input1) {
96
+ this.input1 = input1;
97
+ }
98
+
99
+ public String getInput2() {
100
+ return input2;
101
+ }
102
+
103
+ public void setInput2(String input2) {
104
+ this.input2 = input2;
105
+ }
106
+
107
+ }
108
+
109
+ ```
15
110
  ### 補足情報(FW/ツールのバージョンなど)
16
111
 
17
112
  ・windows10