Geertjan's Blog

  • January 19, 2008

ItsNat in NetBeans IDE

Geertjan Wielenga
Product Manager
I don't know much about the new ItsNat web framework, but enough to know that it is very friendly to NetBeans IDE. When you download and unzip the distro, you'll find you have a NetBeans project. You can then open it in the IDE and deploy it, which will result in a long list of samples being available from the browser.

One of ItsNat's strengths is its IDE agnosticism (same as Wicket). In other words, there are no special artifacts, it simply uses standard Java EE artifacts such as JSP, or HTML, or servlets, or general Java classes. (And no ItsNat-specific servlet or filter needs to be registered in web.xml.) Hence, there's no actual need for a plugin for this framework. However, it would be handy if one, on completion of the web application wizard, would have all the ItsNat JARs (just 4 of them are needed) on the application's classpath.

This absolutely minimal need is interesting enough to create a plugin around, to show the simplest imaginable implementation of the NetBeans API WebFrameworkProvider class, in the context of everything else that is needed to implement it.

  1. Set dependencies on the following:
    • Dialogs API
    • External Libraries
    • File System API
    • Java Project Support
    • Project API
    • Swing Layout Extensions Integration
    • UI Utilities API
    • Utilities API
    • Web APIs

  2. Create a class called ItsNatWebFrameworkProvider that extends WebFrameworkProvider . Even though ProjectClassPathExtender is deprecated, it seems to be the only way of getting the job done. Below is the whole class:

    public class ItsNatWebFrameworkProvider extends WebFrameworkProvider {
    private ItsNatWebModuleExtender panel;//Constructor sets framework name and tip
    //in the Frameworks panel:

    public ItsNatWebFrameworkProvider() {
    super("ItsNat", "ItsNat");
    }//You'll need to test somehow whether the
    //application supports the framework, for the
    //Project Properties dialog. For now, set to true:

    public boolean isInWebModule(WebModule arg0) {
    return true;
    //This method will be called from the panel.
    //It is the method that adds the library to the
    //application's classpath:

    public Set extendImpl(WebModule wm) {
    FileObject fo = wm.getDocumentBase();
    Project project = FileOwnerQuery.getOwner(fo);
    //Name of the library that must be in the Library Manager (see step 3 below):
    Library lib = LibraryManager.getDefault().getLibrary("ItsNat");
    if (lib != null) {
    ProjectClassPathExtender cpExtender = (ProjectClassPathExtender)
    if (cpExtender != null) {
    try {
    } catch (IOException ioe) {
    } else {
    "WebProjectClassPathExtender not found in the project lookup of project: " +
    return null;
    }//This method used to return "ConfigurationPanel",
    //but now returns "WebModuleExtender", which is the
    //lower section of the Frameworks panel. Currently,
    //this can't be null, even though we don't actually
    //need it in this case:

    public WebModuleExtender createWebModuleExtender(WebModule wm, ExtenderController arg1) {
    panel = new ItsNatWebModuleExtender(this);
    return panel;
    }//In this case, no configuration files are needed
    //by the framework, but if they were, such as
    //struts-config.xml, this method would be where you
    //handle this:

    public File[] getConfigurationFiles(WebModule arg0) {
    return null;

  3. Use the "Java SE Library Descriptor wizard" to add the 4 ItsNat JARs to the module. You'll have to go to the ItsNat site and download the distribution, then add the JARs to the Library Manager so that you can use the "Java SE Library Descriptor wizard" to wrap them in the module.

    This wizard will end up causing the ItsNat JARs to be installed in the Library Manager when the module is installed. Since the same module that adds the class above will also add the JARs to the Library Manager, the extendImpl method (defined above) will correctly find the library.

  4. Create a class called ItsNatWebModuleExtender that extends WebModuleExtender. Here is all the code:

    public class ItsNatWebModuleExtender extends WebModuleExtender {
    private ItsNatVisualPanel component;
    private final ItsNatWebFrameworkProvider framework;
    public ItsNatWebModuleExtender(ItsNatWebFrameworkProvider framework) {
    this.framework = framework;
    //Call the method in the frameworkprovider class
    //that will add the library to the classpath:

    public Set extend(WebModule webModule) {
    return framework.extendImpl(webModule);
    }//Return the panel, which is done from the
    //constructor above:

    public JComponent getComponent() {
    if (component == null) {
    component = new ItsNatVisualPanel();
    return component;
    public HelpCtx getHelp() {
    return null;
    public boolean isValid() {
    return true;
    public void update() {}
    public void addChangeListener(ChangeListener arg0) {}
    public void removeChangeListener(ChangeListener arg0) {}

  5. Use the "Wizard wizard". Make it a "Custom" and "Static" wizard, with 1 panel. Click Next and use "ItsNat" as the classname prefix. Click Finish. Refactor the generated classes to rename them to "ItsNatVisualPanel" and "ItsNatWizardPanel". Since we don't need to have the user configure anything, we can just leave these classes untouched. However, since currently null can't be returned (which would make more sense in this case), add a JLabel to the visual panel and then set the text to "No configuration needed." At least this way there'll not be nothing at all under the "ItsNat Configuration" label in the Frameworks panel.

    NB: You can delete the "ItsNatWizardPanel". Why? Because there's no longer integration with the Wizard API. Instead of using the Wizard wizard, it is better to use the JPanel wizard, because all you need is a JPanel here, unlike before in the 5.5 version of the WebFrameworkProvider API class. This is a very good improvement, in my opinion. (For other changes in the 6.0 version of the WebFrameworkSupport class, click here).

  6. Register the framework provider class that you created in the first step above:

    <folder name="j2ee">
    <folder name="webtier">
    <folder name="framework">
    <file name="org-netbeans-modules-itsnatframeworksupport-ItsNatWebFrameworkProvider.instance"/>

Install the module. Create a new web application. In the Frameworks panel, you'll have an entry for "ItsNat". Complete the wizard... and the ItsNat JARs will be found within the Libraries node.

Join the discussion

Comments ( 1 )
  • Jose M. Arranz Sunday, January 20, 2008

    Thanks for your ItsNat mini plug-in.

    A note: ItsNat doesn't need JSP, I only use one JSP file (index.jsp) to start the Tomcat, normal mode and debug mode, on NetBeans :)

    And certainly ItsNat is NetBeans friendly but it's so pure web that is a child game to create a new ItsNat based web project (or set up the Feature Showcase) using any other IDE.

    And finally one idea for your plug-in: ItsNat doesn't provide a predefined servlet (and doesn't want), a very simple wizard can create an ItsNat capable servlet following the recommended set-up: a servlet class (concrete name can be entered) inheriting from org.itsnat.core.http.HttpServletWrapper with an empty init(ServletConfig) method calling the super method. No more predefined typical set up is needed because default values are usually the most appropriated ones. The HttpServletWrapper is very very mimimalist and its code can be generated too (avoiding this inheritance).

    I'm sorry but at this moment ItsNat needs only a pure Java editor and a servlet container, I cannot give you more work to NetBeans :)

    Anyway ItsNat code loves the Java editor and specially the "find uses" and refactoring part (as any other Java program). The HTML editor is nice too for me (I don't need any other). I'm a NetBeans user since Forte days.

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.