This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 125069 - Extending a web project with Spring MVC
Summary: Extending a web project with Spring MVC
Status: RESOLVED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: Spring (show other bugs)
Version: 6.x
Hardware: All All
: P1 blocker (vote)
Assignee: John Baker
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-01-10 22:45 UTC by John Baker
Modified: 2008-02-27 10:37 UTC (History)
0 users

See Also:
Issue Type: TASK
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Baker 2008-01-10 22:45:58 UTC
Task is to extend web project options for the Spring framework framework

Currently in the New Project wizard, frameworks section, there is basic support for creating a Spring Web project.

To provide improved project setup, additional features to be added:

- option to include the jstl.jar library for using JSTL features
- Help context
Comment 1 John Baker 2008-01-14 07:08:37 UTC
SpringConfigPanel now extends WebModuleExtender.
I'll update the change log once available ( I accidently closed the terminal from which I ran cvs)
Comment 2 John Baker 2008-01-14 07:26:50 UTC
Partial changes to use WebModuleExtender

Directory: /web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/
=====================================================================

File [changed]: SpringConfigPanel.java
Url:
http://web.netbeans.org/source/browse/web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/SpringConfigPanel.java?r1=1.7&r2=1.8
Delta lines:  +29 -5
--------------------
--- SpringConfigPanel.java	12 Jan 2008 16:28:01 -0000	1.7
+++ SpringConfigPanel.java	14 Jan 2008 06:45:24 -0000	1.8
@@ -43,10 +43,13 @@
 
 package org.netbeans.modules.spring.webmvc;
 
-import java.awt.Component;
+import java.util.Set;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
-import org.netbeans.modules.web.spi.webmodule.FrameworkConfigurationPanel;
+import org.netbeans.modules.web.api.webmodule.ExtenderController;
+import org.netbeans.modules.web.api.webmodule.WebModule;
+import org.netbeans.modules.web.spi.webmodule.WebModuleExtender;
+import org.openide.filesystems.FileObject;
 import org.openide.util.HelpCtx;
 
 /**
@@ -54,12 +57,22 @@
  *
  * @author Craig MacKay
  */
-public class SpringConfigPanel implements FrameworkConfigurationPanel, ChangeListener {
+public class SpringConfigPanel extends WebModuleExtender implements ChangeListener {
 
     private SpringConfigPanelVisual frameworkPanelVisual;
-
+    private final SpringWebFrameworkProvider framework;
+    private final ExtenderController controller;
     private String dispatcherName = "dispatcher"; // NOI18N
     private String dispatcherMapping = "*.htm"; // NOI18N
+    private boolean customizer;
+    
+     /** Creates a new instance of JSFConfigurationPanel */
+    public SpringConfigPanel(SpringWebFrameworkProvider framework, ExtenderController controller, boolean customizer) {
+        this.framework = framework;
+        this.controller = controller;
+        this.customizer = customizer;
+        getComponent();
+    }
 
     public String getDispatcherName() {
         return dispatcherName;
@@ -75,7 +88,7 @@
         }
     }
 
-    public Component getComponent() {
+    public SpringConfigPanelVisual getComponent() {
         if (frameworkPanelVisual == null) {
             frameworkPanelVisual = new SpringConfigPanelVisual(this);
         }
@@ -106,4 +119,15 @@
         dispatcherName = frameworkPanelVisual.getDispatcherName();
         dispatcherMapping = frameworkPanelVisual.getDispatcherMapping();
     }
+    
+    @Override
+    public void update() {
+       // not used yet
+    }
+
+    @Override
+    public Set<FileObject> extend(WebModule webModule) {
+        return framework.extendImpl(webModule);
+    }
+   
 }

File [changed]: SpringWebFrameworkProvider.java
Url:
http://web.netbeans.org/source/browse/web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/SpringWebFrameworkProvider.java?r1=1.8&r2=1.9
Delta lines:  +17 -23
---------------------
--- SpringWebFrameworkProvider.java	13 Jan 2008 20:07:08 -0000	1.8
+++ SpringWebFrameworkProvider.java	14 Jan 2008 06:45:24 -0000	1.9
@@ -68,9 +68,10 @@
 import org.netbeans.modules.j2ee.dd.api.web.ServletMapping;
 import org.netbeans.modules.j2ee.dd.api.web.WebApp;
 import org.netbeans.modules.j2ee.dd.api.web.WelcomeFileList;
+import org.netbeans.modules.web.api.webmodule.ExtenderController;
 import org.netbeans.modules.web.api.webmodule.WebModule;
-import org.netbeans.modules.web.spi.webmodule.FrameworkConfigurationPanel;
 import org.netbeans.modules.web.spi.webmodule.WebFrameworkProvider;
+import org.netbeans.modules.web.spi.webmodule.WebModuleExtender;
 import org.openide.ErrorManager;
 import org.openide.filesystems.FileLock;
 import org.openide.filesystems.FileObject;
@@ -98,20 +99,20 @@
         super(NbBundle.getMessage(SpringWebFrameworkProvider.class, "LBL_FrameworkName"),
NbBundle.getMessage(SpringWebFrameworkProvider.class, "LBL_FrameworkDescription"));
     }
 
-    @Override
-    public Set extend(WebModule webModule) {
-        EnableFrameworkAction enableFrameworkAction = new EnableFrameworkAction(webModule,
getSpringConfigPanel(webModule));
+    // not named extend() so as to avoid implementing WebFrameworkProvider.extend()
+    public Set<FileObject> extendImpl(WebModule webModule) {
+        CreateSpringConfig createSpringConfig = new CreateSpringConfig(webModule);
         FileObject webInf = webModule.getWebInf();
         if (webInf != null) {
             try {
                 FileSystem fs = webInf.getFileSystem();
-                fs.runAtomicAction(enableFrameworkAction);
+                fs.runAtomicAction(createSpringConfig);
             } catch (IOException e) {
                 ErrorManager.getDefault().notify(e);
                 return null;
             }
         }        
-        return enableFrameworkAction.getFilesToOpen();
+        return createSpringConfig.getFilesToOpen();
     }
 
     @Override
@@ -143,15 +144,10 @@
         return files.toArray(new java.io.File[0]);
     }
 
-    @Override
-    public FrameworkConfigurationPanel getConfigurationPanel(WebModule webModule) {
-        return getSpringConfigPanel(webModule);
-    }
-
-    protected SpringConfigPanel getSpringConfigPanel(WebModule webModule) {
-        if (panel == null) {
-            panel = new SpringConfigPanel();
-        }
+    public WebModuleExtender createWebModuleExtender(WebModule webModule, ExtenderController controller) {
+        boolean defaultValue = (webModule == null || !isInWebModule(webModule));
+        panel = new SpringConfigPanel(this, controller, !defaultValue);
+        // may need to use panel for setting an extended configuration
         return panel;
     }
 
@@ -163,15 +159,13 @@
         return DDProvider.getDefault().getDDRootCopy(webModule.getDeploymentDescriptor());
     }
 
-    private class EnableFrameworkAction implements FileSystem.AtomicAction {
+    private class CreateSpringConfig implements FileSystem.AtomicAction {
 
         private Set<FileObject> filesToOpen = new LinkedHashSet<FileObject>();
         private WebModule webModule;
-        private SpringConfigPanel frameworkPanel;
 
-        public EnableFrameworkAction(WebModule webModule, SpringConfigPanel frameworkPanel) {
+        public CreateSpringConfig(WebModule webModule) {
             this.webModule = webModule;
-            this.frameworkPanel = frameworkPanel;
         }
 
         public void run() throws IOException {
@@ -180,7 +174,7 @@
             WebApp ddRoot = DDProvider.getDefault().getDDRoot(dd);
             addContextParam(ddRoot, "contextConfigLocation", "/WEB-INF/applicationContext.xml"); // NOI18N
             addListener(ddRoot, CONTEXT_LOADER);
-            addServlet(ddRoot, frameworkPanel.getDispatcherName(), DISPATCHER_SERVLET,
frameworkPanel.getDispatcherMapping(), "2"); // NOI18N
+            addServlet(ddRoot, panel.getDispatcherName(), DISPATCHER_SERVLET, panel.getDispatcherMapping(), "2"); // NOI18N
             WelcomeFileList welcomeFiles = ddRoot.getSingleWelcomeFileList();
             if (welcomeFiles == null) {
                 try {
@@ -209,7 +203,7 @@
             copyResource("footer.jsp", FileUtil.createData(jsp, "footer.jsp")); // NOI18N
             copyResource("jdbc.properties", FileUtil.createData(webInf, "jdbc.properties")); // NOI18N
             addFileToOpen(copyResource("applicationContext.xml", FileUtil.createData(webInf,
"applicationContext.xml"))); // NOI18N
-            addFileToOpen(copyResource("dispatcher-servlet.xml", FileUtil.createData(webInf,
frameworkPanel.getDispatcherName() + "-servlet.xml"))); // NOI18N
+            addFileToOpen(copyResource("dispatcher-servlet.xml", FileUtil.createData(webInf, panel.getDispatcherName()
+ "-servlet.xml"))); // NOI18N
 
             // MODIFY EXISTING INDEX.JSP
             FileObject documentBase = webModule.getDocumentBase();


Comment 4 Andrei Badea 2008-01-14 16:45:53 UTC
By the way, when you detect the JSTL library please don't do it by name, but instead try to find the library using a
well-known file or class that should be contained in the libray. Have a look at PersistenceLibrarySupport in
j2ee/persistence to see how that class is used to detect the persistence providers registered in the Library Manager.
Comment 5 John Baker 2008-01-15 11:09:14 UTC
Some updates 

Checking in web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/Bundle.properties;
/cvs/web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/Bundle.properties,v  <--  Bundle.properties
new revision: 1.6; previous revision: 1.5
done
Removing web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/SpringConfigPanel.java;
/cvs/web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/SpringConfigPanel.java,v  <--  SpringConfigPanel.java
new revision: delete; previous revision: 1.9
done
Checking in web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/SpringConfigPanelVisual.form;
/cvs/web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/SpringConfigPanelVisual.form,v  <-- 
SpringConfigPanelVisual.form
new revision: 1.4; previous revision: 1.3
done
Checking in web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/SpringConfigPanelVisual.java;
/cvs/web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/SpringConfigPanelVisual.java,v  <-- 
SpringConfigPanelVisual.java
new revision: 1.6; previous revision: 1.5
done
Checking in web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/SpringWebFrameworkProvider.java;
/cvs/web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/SpringWebFrameworkProvider.java,v  <-- 
SpringWebFrameworkProvider.java
new revision: 1.10; previous revision: 1.9
done
RCS file: /cvs/web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/SpringWebModuleExtender.java,v
done
Checking in web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/SpringWebModuleExtender.java;
/cvs/web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/SpringWebModuleExtender.java,v  <-- 
SpringWebModuleExtender.java
initial revision: 1.1
done
Comment 6 John Baker 2008-01-17 07:39:01 UTC
Added JSTL support (new checkbox in the framework dialog)

Checking in web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/Bundle.properties;
/cvs/web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/Bundle.properties,v  <--  Bundle.properties
new revision: 1.7; previous revision: 1.6
done
Checking in web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/SpringConfigPanelVisual.form;
/cvs/web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/SpringConfigPanelVisual.form,v  <-- 
SpringConfigPanelVisual.form
new revision: 1.5; previous revision: 1.4
done
Checking in web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/SpringConfigPanelVisual.java;
/cvs/web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/SpringConfigPanelVisual.java,v  <-- 
SpringConfigPanelVisual.java
new revision: 1.7; previous revision: 1.6
done
Checking in web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/SpringWebModuleExtender.java;
/cvs/web/spring/webmvc/src/org/netbeans/modules/spring/webmvc/SpringWebModuleExtender.java,v  <-- 
SpringWebModuleExtender.java
new revision: 1.2; previous revision: 1.1
done
Comment 7 Andrei Badea 2008-02-27 10:37:53 UTC
Implemented, so closing.