- PR -

htmlタグライブラリのcancelについて

1
投稿者投稿内容
Yasyu
会議室デビュー日: 2004/11/04
投稿数: 9
投稿日時: 2004-11-10 21:06
2度目の投稿です。

使用している環境は以下の通りです。
 WindowsXPPro SP2
 Tomcat 5.0.29
 JDK 1.4.2_06
 Struts 1.2.4

struts1.2.4でJSPを製造しているのですが、
htmlタグライブラリのcancelタグをJSP内のボタンに
割り当てているのですが、validateが回避できません。

*** JSP ***
<html:cancel property="button5" value="一覧に戻る" />
<html:submit property="button1" value="入力完了" />
<html:reset property="button2" value="初期状態に戻す" />

*** struts-config.xml ***
<action
name="LogonForm1"
path="/logon1"
scope="request"
type="Men.Tan.action.LogonAction1"
input="/jsp/logon1.jsp"
validate="true" >
<forward name="form2" path="/jsp/logon2.jsp" />
<forward name="list" path="/jsp/logon0.jsp" />
<forward name="form1" path="/jsp/logon1.jsp" />
</action>

*** Men.Tan.action.LogonAction1.java ***
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {

if( request.getParameter("button5") != null ) {
return mapping.findForward("list");
} else if( request.getParameter("button1") != null ) {
return mapping.findForward("form2");
} else {
return mapping.findForward("form1");
}
}

validate実行後にどんなメソッドを呼び出しているのか
分かっていないので、何が原因なのか分かりません。

どんな原因が考えられるのでしょうか?
教えてください。
でくのぼう
大ベテラン
会議室デビュー日: 2003/10/06
投稿数: 162
投稿日時: 2004-11-10 21:11
特に必要が無ければ cancel の property を指定するべきではないのでは?

http://struts.apache.org/userGuide/struts-html.html#cancel
には以下のように書かれています。

引用:

WARNING - If you set this attribute to a value other than the
default, this will NOT be recognized as the cancel key by the Struts
controller servlet or the Action.isCancelled() method. You will need to
do your own cancel detection.



素直に

コード:
<html:cancel value="一覧に戻る"/>



と記述して Action 側では

コード:
if (isCancelled())



で判別してはどうですか?
Yasyu
会議室デビュー日: 2004/11/04
投稿数: 9
投稿日時: 2004-11-11 09:39
ご回答ありがとうございます。

ご指摘のとおりに修正したところ正しく動作しました。
struts歴がまだ10日で、分からないことばかりなので、助かりました。
ありがとうございました。
1

スキルアップ/キャリアアップ(JOB@IT)