Hi all, We are currently trying to split an existing Struts application into sub-modules, but it seems it is not as easy as it is usually said in the short articles we have found about it.
So, I'll try to explain a bit more where we are and what we have done until now. 1. File structure ----------------- We have a classical Struts web-app directory structure, with a sub-module as follows: *.jsp /WEB-INF - web.xml - struts-config.xml - tiles-definitions.xml - validator.xml /lib /classes/ourPackage - *.java /scripts /stylesheets /templates /testsubmodule *.jsp /WEB-INF - struts-config.xml /classes/ourPackage - *.java 2. Web.xml ---------- In our web.xml file, we have added the following xml for the new sub-module: <init-param> <param-name>config/testsubmodule</param-name> <param-value>/testsubmodule/WEB-INF/struts-config.xml</param-value> </init-param> 3. struts-config.xml -------------------- Then we have added the necessary ActionMapping entries for this sub-module. These definitions are loaded and the mapping is working fine. We only have ActionMapping AND FormBeans really used by this module. Anyway, sometimes determining which FormBeans from your root application is also used by your sub-module is not easy. Duplicating everything can maybe be an easy solution. As far as we have read and from our experience, it seems that RequestProcessor, MessageResources and PlugIns have to be duplicated from the root struts-config.xml file. Is this correct ? We have also created a SwitchAction and a global forward: <forward name="gotoTestModule" path="/toTestModule.do?page=/bodyTest.jsp&prefix=/testsubmodule" /> and <action path="/toTestModule" type="org.apache.struts.actions.SwitchAction"/> As the path attribute is context-relative, there can be a mapping in the root that has the same name as one in the sub-module, i.e. http://myserver/myapp/myaction.do is different from http://myserver/myapp/testsubmodule/myaction.do 4. JSP and Tiles ---------------- Of course, accessing the stylesheets, scripts and templates from the JSP files in the sub-modules must be context (path) relative too. So one solution is to use a relative path to the files, i.e. ./stylesheets/mycss.css for JSP in the root directory, and ../stylesheets/mycss.css for JSP contained in the testsubmodule directory. Another solution can be to use a <BASE> tag in order to set the base URI to the application URI. As we are using tiles, this tag can be added in the main tile file. But in this case, it is important to take care about links used in the JSP. But can it lead to unexpected problems ? 5. Java ------- Access to Java objects doesn't seem to have problems in the sub-module, wherever they are located (root or sub-module), if the objects in the sub-module are well compiled. 6. Problems ----------- Seems that our main problems are due to incorrect context. First of all, as we use tiles, and that the main tile template is contained in the root, <html:form> and calls to mapping.getName() inside the template JSP are NOT in the sub-module context. So the ActionMapping defined in the sub-modules are not known. Well, first of all, we don't use the SwitchAction yet, but will it solve our problem ? Also another solution may be to duplicate the template tile in our sub-module, and use it instead of the one in the root directory. For the moment, we have found in the mailing list archive what I would call a temporary solution, using org.apache.struts.util.RequestUtils.selectModule("testsubmodule",request,application) before any form or call to the mapping Object. Another problem is that we are using a tile with two frames. If the first one is an action from the root directory, and the second frame is an application from the sub-module, and that they are called from a JSP in the sub-module, then we can use the SwitchAction to call both parts. But the problem is that the final context will be the last one called, i.e. the one from the second frame. So if we do some action in the part from the root directory, it doesn't work as it thinks the context is now the one of the sub-module. Well, in general, it seems not easy, and needs more care, to be sure to be in the right context for any action that can be made from one JSP, which can be a headache if you are using multiple tile levels. So, if anyone can help us giving some good pieces of advice regarding our current work, or to complete this text, he/she is welcome. If I've got new information, I'll add it to this thread too. Thanks a lot Alexandre Dumortier ===== KARMA Project - Development Team __________________________________ Do you Yahoo!? Yahoo! Finance: Get your refund fast by filing online. http://taxes.yahoo.com/filing.html --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]