問題描述
當 Action 類位於單獨的 jar 文件中時,Struts 2 驗證失敗 (Struts 2 Validation failing when Action class sits in a separate jar file)
I have a maven multi-module project.
project-services (service layer..above the dao layer)
project-controller (My Action classes sits in this module)
project-web (all jsps, view artificats)
The issue is I have a valid DefaultProjectsAction-validation.xml in the package with DefaultProjectsAction.java as well as the properties file.
All these modules, when the war file is deployed will be in /WEB-INF/lib. I use in struts.xml the default package. All files are correctly set-up. Spellings errors on the the file names checked properly. Will my struts validations work if the validation xml files are in a seperate jar. I read somewhere where they say it should be in WEB-INF/classes/. Is this the reason why my struts form can't be validated?
參考解法
方法 1:
Ok it's exactly 48 hours since I started looking at this problem and ladies and gentlemen the solution has been found.
Putting struts 2 action classes on a seperate module and validation set-up has to go like this.
project-controller (will have action classes for Struts 2 in this case)
- com.pack.UserAction.java
The solution is to create a source folder src/main/resources/com/pack (Maven project) in project-web module and put UserAction-validation.xml in there. Like this
project-web (views, jsps, properties files and set-up files)
- src/main/resources/com/pack/UserAction-validation.xml
The file will be copied to /WEB-INF/classes/com/pack (The action class package should form the path) and on building the project
(by Bobby T Jakachira、Bobby T Jakachira)