Module Creation Tutorial
Config Files – several config files need to be altered to create the new module ***struts.xml**** The struts.xml located at WEB-INF/config/struts.xml, is the main configuration file for the Struts Framework. See: http://jakarta.apache.org/struts/userGuide/building_controller.html#config The basicportal application uses the name struts.xml instead of the struts-config.xml outlined in the user guide. Several changes need to be made to the document that comes with basicportal install these changes will be outlined. - Naming conventions to keep in place during alteration of file -action path are in reverse camelback notation action path="/port/projTasksModule" -forward paths are in camelback notation also path="projTasksZoom.portlet" -form bean names are in camelback notation name="storeBean" Additions to file for a new Module We will use the entries for the projTask Module as templates for our new entries for the new module. (See struts.xml) A new formbean must be added to the struts.xml for each module in the below example the bean's source file is org.apache.store.StoreBean and the name is "storeBean" <form-beans> <form-bean name="storeBean" type="org.apache.store.StoreBean"/> </form-beans> New actionpaths need to be created for the module <action path="/store/store" type="org.apache.commons.dispatch.StrutsSimpleAct" name="storeBean" scope="session" validate="false"> <forward name="Success" path="store.module"/> </action> <action path="/store/storeModule" type="org.apache.store.StoreModule" name="storeBean" scope="session" validate="false"> <forward name="Zoom" path="storeZoom.portlet"/> <forward name="Success" path="storeLst.portlet"/> </action> ****layouts.xml**** layouts.xml located at WEB-INF/config/layouts.xml is the central place for our tiles definitions. For a tutorial on tiles see: www.lifl.fr/~dumoulin/tiles/ naming conventions – it is important to match up the names from struts.xml with the layouts.xml where they are related. be carefull to spell names exactly the same **Additions for new module** New definitions need to be created: For the example store module they are <!—storeLst ? <definition name="store.module" path="/do/store/storeModule"/> <definition name="storeLst.portlet" extends="baseDef"> <put name="body" value="/portlets/store/StoreLstPortlet.jsp"/> </definition> <definition name="storeZoom.portlet" extends="baseDef"> <put name="body" value="/portlets/store/StoreZoomPortlet.jsp"/> </definition> The first definition above is the "default" definition for the Module, if you look into the struts.xml file you will see that the definition links to the org.apache.store.StoreModule file we will create. (This is the controller in our MVC architecture) Also notice in the stuts.xml file that there are two forwards associated with this default controller. The second two definitions above are created to match these forwards. Also notice that The put tags within the definitions override the values in the baseDef. Java Source Files 3 Types **Modules** are the controller portion of the MVC architecture The "Module" java class files ie. org.apache.store.StoreModule are the link between the view and the model component --methods in the source file-- -onDisplayExec controls the LST process -onDisplayZoom controls the Zoom process -onSaveExec saves changes to the model -onNewExec new record creation We will use the TasksModule.java as the template for creating our new StoreModule file it is suggested you edit the TasksModule: -replace all references to TaskBean with reference to (StoreBean) the name of your modules Bean file. -change name of class to (StoreModule) the name of your module. -change package name ie. package org.apache.store; At this point in our study we are concentrating on USING the framework provided by basicportal to get our new module functioning. Don't get bogged down in the specifics of the logic in this module. (Drive… you can look under the hood later!) **Beans** part of the struts architecture… not quite the model but the Beans act as the transfer agent from the view to the Model. We will use the TasksBean.java file as the template for our new (StoreBean) file. - Change name of class and package to appropriate values for your class. Methods: find(): change references to TaskDAO to (StoreDAO) your DAO class findAll(): change references to TaskDAO to (StoreDAO) your DAO class getter and setter methods: public void setTaskName(String arg) { getDAO().setProperty("task_name",arg); } public String getTaskName() { return(String)getDAO().getProperty("task_name"); } Add one set of getter and setter methods for each field in your table. Follow naming format of lowercase for column name and camelback notation for method name. test(): implement test method to call getters and output values **DAO** these files encapsulate the CRUD processes and enable simple interaction with the database We will use the TasksDAO.java file as a template for our new DAO file (StoreDAO). Methods: retrieveAll and retrieve(): change the setTableName method call parameter to the name of your table: getCR().setTableName("proj_task"); also change the sql string variable to match your table: String sql = "select * from \"proj_task\""; ***JSP Files*** LST – List mode of our Module This file is the vies for the list mode of our Module it's function is to list the records needing to be display in a table and provide links so that the Zoom method may be called to edit individual records. Page also has a link to create a new record We will use the TaskLstPortlet.jsp file as a template. This page uses the JSTL tag libraries. For info on the JSTL tags see the .pdf file on the basicportal site at sourceforge. ? -There are several calls to create urls on the page replace value="/do/port/tasks" with a corresponding value="/do/store/store (for store module customize this for your module) -assuming your primary key column in your table is id leave the following code intact: <c:param name="ID" value="${requestScope.formBean.id}"/> (adjust for your primary key column if needed) -output column values using: <c:out value="${requestScope.formBean.name}"/ (replace field name with appropriate value for your bean) Zoom – Zoom mode of the module This file is the View for the Zoom mode of the Module it's purpose is to provide fields for insertion and update of records. We will use the TaskZoomPortlet.jsp file as the template. -replace action URL for form with appropriate value for your module ie action="/store/store -Provide input fields with html:text tag for each field in your table: For example: Item Name * : </td><td> <html:text size="70" property="name"/> </td></tr> <tr><td> Congratulations!!!! You should be ready to test your Module!!!! Summary Steps in Producing a new Module 1 Create SQL and table 2 Customize XML files 3 Create Bean File – code test method in Bean class and test 4 Create DAO Files 5 Create Module Files – (important) it is suggested that you implement the onDisplayExec method in your module with a call to system.out.println("I got here") to make sure your module code is being called 6 Create JSP files 7 Test LST file – (ie. browse to /do/store/store) 8 Test Zoom File – (ie. browse to /do/store/store and click on edit buttons) 9 Add Module to Navigation Menus (edit common/leftBar.jsp) _______________________________________________ MVC-Programmers mailing list [EMAIL PROTECTED] http://www.netbean.net/mailman/listinfo/mvc-programmers