Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

2009-09-23

My Eclipse settings

Eclipse is a great Java IDE. There are just a few things I don't like about its default configuration. Fortunately, it's highly configurable.
  • Preferences
    • General
      • Ant
        • Editor
          • Formatter
            • Tab size: 3
            • Use tab character instead of spaces: uncheck.

      • Editors
        • Displaced tab width: 3
        • Insert spaces for tabs: Check.
        • Show line numbers: Check.
        • Text Editors
          • Spelling
            • Enable spell checking: Uncheck.


    • Java
      • Code Style
        • Qualify all generated field accesses with 'this.': Check.
        • Formatter: new profile "carl"
          • Indentation
            • General settings
              • Tab policy: Spaces only
              • Indentation size: 3
              • Tab size: 3


      • Compiler
        • Errors/Warnings
          • Potential programming problems
            • Serializable class without serialVersionUID: Ignore

      • Editor
        • Folding
          • Initially fold
            • Imports: uncheck.


2009-07-22

import static in a JSP

I have yet to try this, but according to this post on the GlassFish forum, the way to do an "import static" in a JSP is like this:

<%@ page import="static foo.*" %>

Implementing an interface in a JSP

I've scoured the net, but apparently it's not possible to make a Java Server Page implement an interface. Not directly, anyway.

What is possible is to extend a class. The directive is:

<%@ page extends="package.class"%>


One reference for JSP page directives is: http://java.sun.com/products/jsp/tags/11/syntaxref11.fm7.html .

The class generated from a JSP usually extends HttpServlet. If you really want to have your JSP implement an interface, you could do something like

public abstract class
my.package.MyJSP extends HttpServlet implements MyInterface {

}

... and then use "my.package.MyJSP" in a "page extends" directive as shown above.

The caveat to this is that some Web containers will generate their own subclasses of HttpServlet, presumably for some kine of optimization, and using the "page extends" directive will sabotage this scheme. It should still work, it just won't include the fancy footwork your Web container intended to do.

2009-05-01

Mixing Java and Scala in an Eclipse Project

If you start a project off as a Scala project, then it's OK to mix in some Java source. Everything will be compiled as appropriate, and library references will work out too.

But for some projects, such as the "Dynamic Web Project," that's not an option. You must convert it to a Scala project after it's created as a Java project.

Fiddling with the contents of .project manually didn't get me anywhere.

The correct procedure, as found on Nabble, is:

As a general rule you should convert Java projects to Scala projects
by using the "Add Scala Nature" package explorer context menu action
unless you know what you're doing.

2009-04-18

Simulating a manual window close

w.getToolkit().getSystemEventQueue().postEvent(new WindowEvent(w, WindowEvent.WINDOW_CLOSING));

obtained (with thanks) from: http://forums.java.net/jive/thread.jspa?threadID=35565

This will fire the WindowClosing event, so you can execute any action you may have bound to that event.