Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 [FAQ小组]arch:Struts FAQ 系列之7月4日 [精华]
haibo



CJSDN高级会员


发贴: 322
积分: 71
于 2003-07-04 12:38 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
问题:
我有一个应用程序用了30个表单,用的是动态formbean.这30个表单用一个Action来处理,我是否 必须指定相对应的30个ActionMapping(译者注:就是action)在Struts的配置文件中?我应该怎样来处理?

回复:
这主要依据你采用的验证方式。实际上,你确实需要为每一个不同的验证实例创建一个action,其中每一个要么用普通actionform,要么用动态formbean来实现验证(validation)操作.
如果你使用的是动态formbean,那么你一定想用到struts validator.你可以为每个验证实例创建一个 validator form.(译者注:即创建一个动态formbean包含30个表单的所有子段)然后设置action 的attribute属性为这个formbean对应表单的名称。这样,所有的action对应一个formbean(但是验证时是验证不同的属性集合)(译者注:即对应30表单有30个不同名称的action,在validation.xml中依据action名称来查找所需的验证,你所采用的动态bean要为DynaValidatorActionForm类型).DynaActionForm可包含不必要的字段,这样没有害处。
如果你采用的是普通formbean,那么你也可创建一个base formbean包含所有的属性,然后按照相应的验证需求继承出每一个子类,在这些子类中overwrite validator()方法实现所需的验证逻辑。
HTH,Ted
Ted Husted,(译者注:<<struts in action>>一书作者)

原文如下,译自jguru.com,希望对网友有用,其中加入了自己观点,请指教,工作太忙,每天一例。

Question:
I have an application which has around 30 forms.We are using dyna action forms. I have one action which has to be called from all these 30 forms. So do I need to have to need 30 mappings in the config file for each form? How will I handle that.. Thanks for the help, Manoj.

Answer :

It mainly depends on the validation needs. In practice, you do need an action-mapping each distinct validation that Struts must handle itself. Each of these action-mappings then need either a ActionForm or a Validator form to provide the validation behavior. if you are using DynaActionForms, then you probably want to use the Struts Validator. You can create a Validator form for each validation instance. Then set the attribute property of the ActionMapping to match the Validator form name. The action-mapping can then all share the same form-bean (but validate a different set of properties). The DyanActionForm may define properties that some of the forms don't use, but that does no harm. (See also "Coarse-grained ActionForms").

If you were using conventional ActinForms, then you could create a base ActionForm with all the properties that your forms needed, and then a subclass for each validation. Then, instead of creating Validator forms you could create a form-bean for each validation instance.

HTH, Ted

--
Ted Husted,


haibo edited on 2003-07-04 13:50



话题树型展开
人气 标题 作者 字数 发贴时间
2155 [精华] [FAQ小组]arch:Struts FAQ 系列之7月4日 haibo 2152 2003-07-04 12:38

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2020 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号
客服电话 0592-8750026    客服信箱 714923@qq.com    客服QQ 714923