Forums: Open Discussion (Thread #19474)

requestにセットしたメッセージが消える (2008-07-30 16:34 by Anonymous #37927)

お世話になります。

For Java WEB での事象なのですが、
画面の初期表示時にBLogicでメッセージをセットし
その後の登録ボタンでvalidateで弾かれると、
メッセージが消えてしまいます。

AbstractBlogicAction#setSaveMessageScope(String saveMessageScope)
を使わずに値を保持する方法はありますでしょうか。

--Blogic--
BLogicMessages messages = new BLogicMessages();
messages.add("comment_01",
new BLogicMessage("errors.required", id));
result.setMessages(messages);

--JSP--
<html:messages id="message" property="comment_01" message="true">
<bean:write name="message"/>
</html:messages>


<html:messages>でメッセージを表示し

Reply to #37927×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: requestにセットしたメッセージが消える (2008-07-30 17:12 by hachihachi #37928)

AbstractBLogicActionにsaveMessageScopeという設定があります。
メッセージはデフォルトでは request に保存されますが、saveMessageScopeに session と指定することにより、メッセージをセッションに保存することができます。

以下、機能サンプルのmessageexモジュールからの抜粋です。
<bean name="/messageex/requestScope" scope="prototype"
class="jp.terasoluna.thin.functionsample.messageex.web.action.MessageExRequestScopeAction" >
<property name="saveMessageScope" value="request"/>
<property name="scopeService">
<ref local="scopeService" />
</property>
</bean>
Reply to #37927

Reply to #37928×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: requestにセットしたメッセージが消える2 (2008-07-30 17:16 by hachihachi #37929)

間違えました。
saveMessageScopeがrequestになっていますが、sessionと読み替えてください。
Reply to #37927

Reply to #37929×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: requestにセットしたメッセージが消える3 (2008-07-30 17:59 by hachihachi #37930)

すみません、前提のところを見逃しておりました。
忘れてください。
Reply to #37927

Reply to #37930×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: requestにセットしたメッセージが消える4 (2008-07-30 18:03 by hachihachi #37931)

valudateエラー時の遷移先を、初期表示時のBLogicにするのはいかがでしょうか?
Reply to #37927

Reply to #37931×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: requestにセットしたメッセージが消える (2008-07-30 19:56 by Anonymous #37939)

お早い返信ありがとうございます。

登録ボタンを押した時に入力されていた値も保持しておきたいので、
初期表示のBLogicをそのまま呼ぶだけでなく、
新しくBLogicを作成する必要が出てきそうです。
BLogicが増えすぎてしまうと管理が大変になるので
できれば避けたいです。

前提条件として
システム開発制約として個々のBLogicでは
sessionを使えない(使わない)ようになっております。
わかりづらくて申し訳ありません。


struts-cookbook-1.3.8.warをimportし、
似たようなコードを記述したところ、
strutsではメッセージが消えずに残っておりました。
validate後の遷移先はjspが指定されています。

テラソルナのAbstractBLogicActionでも、
addMessages(request, messages);
は行っているようですが、挙動が違って見えるのは
設定の問題なのでしょうか?
それともテラソルナの拡張部分なのでしょうか?

--テストコード:StrutsのActionClass--
ActionMessages messages = new ActionMessages();
messages.add("comment_01",new ActionMessage("errors.required","hoge"));
addMessages(request, messages);

Reply to #37927

Reply to #37939×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: requestにセットしたメッセージが消える6 (2008-07-30 20:04 by Anonymous #37941)

申し訳ありません。
確認ミスです。

strutsでも消えておりました。
う~ん・・・
やはりsessionにいれるしかないのでしょうか。
Reply to #37927

Reply to #37941×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: requestにセットしたメッセージが消える6 (2008-07-30 20:35 by kimumasa #37945)


メッセージをリクエストスコープにしていれば
StrutsでもTERASOLUNAでもリクエストのライフサイクルに従い、メッセージは消えてしまいます。

対応としてはsessionに入れることをお勧めしますが
強引にリクエストスコープのまま
メッセージを残す場合、
・hidden項目でもメッセージの文言を出力しておいて
 次のリクエストにもデータが残る形にする。
・JSPでサーバ側から送られてきたメッセージを表示できるように書いておく。
※アプリ全体として統一的に対応するなら
 RequestProcessorでも構いませんが、
 processValidateの実行前までに仕組みを
 入れる必要があります。

ちょっと出先でStruts等を動かす環境がないので
検証出来ていませんが、ご参考まで。
Reply to #37941

Reply to #37945×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: requestにセットしたメッセージが消える6 (2008-07-31 08:53 by Anonymous #37959)

出先からわざわざありがとうございます。

対応案
1.sessionにいれる
2.hiddenにいれる
3.RequestProcesserなど、processValidateの前に仕組みをいれる

を調査していこうと思います。

2.に関しては次のリクエストにもデータが残るため、使いやすそうな印象です。
アプリとして巧くつくり、個々が意識しない作りにできれば、
と思います。
3.に関してはお恥ずかしながら詳しい知識がありませんので、調査したいと思います。
Reply to #37945

Reply to #37959×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: requestにセットしたメッセージが消える6 (2008-07-31 11:55 by kimumasa #37961)

おそらく
> 2.hiddenにいれる
で対応できるかと思いますが、補足です。


TERASOLUNA Server Framework for Java(Web版)での
RequestProcessorの情報参照先です。

RequestProcessorEx
http://terasoluna.sourceforge.jp/javadoc/server-web_2.0.1.0/jp/terasoluna/fw/web/struts/action/RequestProcessorEx.html

実装方式にもよりますがprocess、processPopulateメソッドを
オーバーライドするか
org.apache.struts.action.RequestProcessor#processValidate
あたりに細工をすることになるかと思います。


他に、TERASOLUNAでもっている機能で参考になりそうな
コードとしては
jp.terasoluna.fw.web.struts.taglib.MessagesPopupTagとMessagesTagがあります。

実装方法として一旦、Sessionにデータを入れるものの
表示タイミングでSessionからデータを削除し、ゴミが残らないよう
に工夫してあります。
短いコードですし、機能説明書にも記載しているので
参照していただければと思います。

ご参考まで。
Reply to #37959

Reply to #37961×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login