ActionForm为什么不能转LazyDynaBean

来源:互联网 发布:北京线下编程培训班 编辑:程序博客网 时间:2024/04/29 23:24

我是struts初学者,在Struts in Action 这本书上看到了LazyDynaBean这段例子,想把它用在我的开发上,却发现在Action的execute()函数中,我想把用户输入的表单参数提取出来时,ActionForm不能转LazyDynaBean.

上网找了好久,中文资料基本没有提到,后来找到一段英文资料:

 

LazyDynaBean Gotchas

The above solution using LazyDynaBean looks like a simple drop inreplacement which is great, however it assumes that the Struts Validator isactive. If you are not familiar with the validator (I wasn't when I gotdirected to this page for a solution) then it can cost you a number of hours ofhead scratching and frustration whilst you figure it out. To summarise andhopefully give someone a kick start to this, you need to:

1. Include the Commons Validator jar inyour project.

2. Modify your struts-config.xml toinclude the validator plugin.

3. Copy the the validator-rules.xmlfile from the struts download or source one from somewhere else.

4. Create and amend the valilation.xmlfile to include a section for each of your forms you wish to use LazyDynaBeans for.

I found the struts doco assumed you already knowhow all of this worked so wasn't much help to getting started. The best placeto find help is in referenced resources down the bottom of http://struts.apache.org/userGuide/dev_validator.html

 

 

才发现,原来要使用LazyDynaBean,前提是我们已经用了validator框架,而我之前没有用,所以无论怎样都无法弄出来。

相信有些初学者会犯同样的错误,在此提出,希望能帮到有需要的人。