Download NetBeans!

20050831 Wednesday August 31, 2005

Even More Struts and JSF Support in NetBeans IDE Dev!

In Being Greedy: Instantaneous Struts and JSF Support in NetBeans IDE, I demonstrated how tightly integrated Struts and JSF will be in the next release of NetBeans IDE. Later I found out that there'll also be file-level templates, and so I added screenshots for those to the comments at the end of that blog entry. However, yesterday I discovered that Struts and JSF support will go even further than I had thought.

Firstly, let's look at the Struts configuration file (struts-config.xml). Open it in the Source Editor. Now right-click anywhere and notice that... there's a whole new submenu in the contextual menu:

When you choose one of the items, you get a dialog box where you can fill in some values. Then you click OK and the XML is created for you and put in the appropriate place in the configuration file.

Secondly, let's take a look at the the JSF configuration file (faces-config.xml). Same story -- right-click in the Source Editor and you'll see a new submenu with items for common entries in the file:

If you're familiar with the new Palette (described here), you might think: "Hmmm. Wouldn't those items for Struts and JSF fit quite nicely in the Palette? After all, their behavior is the same as for the other items in the Palette." This is true. From what I've been told, that's the plan for the release after the upcoming release.

Aug 31 2005, 08:48:53 AM PDT Permalink

Download NetBeans!

20050830 Tuesday August 30, 2005

Exposing Generated Web Service Client Files in the NetBeans Projects Window

In Eating Web Services in NetBeans IDE 4.1, I complained about the fact that the client files generated by the NetBeans Web Service Client wizard end up stuck away deep in the Files window:

Of course, the extent to which the generated client files are hidden depends on the number of subpackages that you define for them. However, nonetheless, your generated client files are stuck far away from where you would want them -- the Projects window, where you work with the JSP, servlet, or other Java class that uses these client files to interact with the web service. If, for example, there's a getQuote method made available by the web service, you can see that very easily by looking in the Web Service References node in the Projects window. However, what if the web service includes complex types, which the IDE converts to Java POJOs? You need to do a lot of digging to work out (a) what the Java POJOs are and (b) what methods they make available.

Today I was told by Milan Kuchtiak about a very cool workaround (which has one very fatal flaw), specifically for the situation described above. Right-click the project node and then, in the Project Properties dialog box, add the top-level package in which the generated client files are found as a source root in the Sources panel (click to enlarge):

The benefits of doing this are as follows:

  • The folder that you specified immediately appears in the Projects window:

  • Code completion is available in the Source Editor for the generated client files:

  • When you press Alt-Shift-O (Go To Class), the classes are found (although, why they're found twice is a bit of a mystery to me):

However, one big disadvantage is that you shouldn't assume that you can now add Java classes to that new folder in your Projects window! As soon as you run the Clean Project command, they'll be gone. (On top of that, of course, you shouldn't ever want to add files to that package anyway -- it's only there for your generated client files.) And that's probably why the generated client files aren't displayed in your Projects window by default -- files that are deleted during a Clean Project command are never exposed in the Projects window by default. However, if -- as in this scenario -- you need them to be there, you can take the steps to put them there manually, by yourself, and not blame anyone other than yourself when you accidently forget that the folder is going to be deleted the very next time you choose Clean Project...

Aug 30 2005, 09:32:34 AM PDT Permalink

Download NetBeans!

20050829 Monday August 29, 2005

Hot Hot Hot NetBeans Plug-in Developments

What follows is so hot off the presses that it's all still sizzling...

  • Firstly, check out all the cool file-level templates that NetBeans IDE Dev offers you for plug-in development (click to enlarge):

  • Secondly, when you choose "Action" in the File Type list above ("Action" was added very very recently -- in fact, 2 hours prior to my writing this blog entry), one of the panels is truly fantastic. It lets you specify where exactly (and I mean exactly) you want the new action to appear -- not only whether it should be made available by a menu item, toolbar button, file type, or editor, but also before and after which existing action (click to enlarge):

  • Thirdly, if worries about branding support were keeping you up at night, worry no more! There's a new panel added to Module Suite Projects. The top screenshot shows the default, the bottom shows the panel for Rich Unger's FeedReader plug-in module (click to enlarge):

If you've been following developments in the NetBeans plug-in support area, you'll be aware that a lot of time, effort, and skill have been invested in this area over the last few months. It's all looking really good -- the attention to detail (such as the fact that the "Action" wizard -- as shown above -- presents all the available folders, so that you don't have to hunt around for their names as you used to have to do when typing everything manually in the XML Layer) is really quite awesome.

Aug 29 2005, 03:23:02 AM PDT Permalink

Download NetBeans!

20050828 Sunday August 28, 2005

Simple NetBeans Filesystem Manipulation in NetBeans IDE Dev

One really cool and very recent addition to NetBeans plug-in module support is that when you expand the XML Layer node in the Projects window, you can see all the folders defined for the current module within the context of all the folders that are defined in the NetBeans filesystem (click to enlarge):

A nice touch is that the 'this layer in context' node shows the current layer's contributions in bold. This way, you can easily see where and how the current module extends the existing folders in the NetBeans filesystem. In addition, you can drag and drop a folder and the XML in the layer file will follow suit -- this means that there's no need to type those nasty little <attr> tags for ordering items within folders. Yay!

Aug 28 2005, 08:14:27 AM PDT Permalink

Download NetBeans!

20050826 Friday August 26, 2005

4.2... 4.5... 5.0... or what?

Click here and you'll get here...

Cool, right? So go vote.

Aug 26 2005, 05:07:02 AM PDT Permalink

Download NetBeans!

20050825 Thursday August 25, 2005

Options, Options, We Want Options!

Remember this...

Well, forget about it. Here's a short tour through a whole new world (click to enlarge each screenshot):

General panel

Editor panel

Fonts & Colors panel

Keymap panel

Advanced panel

I spotted one spelling mistake in the screenshots above... can anyone else see it?

Hmmm... I see Roman also blogged about this. Is more proof necessary that this is a truly awesome step forward for NetBeans?

Aug 25 2005, 01:44:01 AM PDT Permalink

Download NetBeans!

20050824 Wednesday August 24, 2005

Playing Chess with NetBeans IDE (Part 3)

Now that web service support is available in Java applications, I've been making a lot of progress with the chess web service's client implementation. First, a picture -- this is what things look like right now (click to enlarge):

So, you make your move by adding a piece to the JLayeredPane.DRAG_LAYER and releasing it in a new square. Then (and this is the part that I'm still working on) you need a FEN string that represents the current state of the board, the active color, and the move number. (I'm temporarily using this FEN generator -- first I simulate the move in the FEN generator and then I copy the FEN string into the textfield at the bottom of my chess client.) When I click 'Send FEN', the FEN string is sent to the web service. (What's also sent is the search depth -- if your selected opponent is William Shakespeare, search depth is '5'. If your selected opponent is Alfred E. Neuman, search depth is '1'. In other words, this sets the difficulty level of the response move.)

When the web service returns (literally two or three seconds later, normally even less than that), all it gives you is the move (in the textfield at the top of the chess client), for example:

d7d5

This is all you get back from the web service. This is really great! Imagine, for example, if the web service returned another FEN string -- you'd have a lot of work to do to parse it and work out what to do with it. However, now that I know that the web service's response is 'd7d5', here's what I do -- for the start position -- to break it down into the letter part ('d') and the number part ('7'):

String move = myNorthField.getText();
String startposition_letter = move.substring(0,2);
int startposition_no = Integer.parseInt(move.substring(1,2));

(I do something similar for the end position, to attain the 'd' letter and the '5' number from 'd7d5'.)

So now I know the startposition letter for 'd7d5' is 'd' and the start position number is '7'. But how does the application know where this letter and position are found? It doesn't know that -- all it's done is attribute a number to a square. Here's the code that sets up the board:

public ChessBoard() {

    Dimension boardSize = new Dimension(500, 500);

    //  Create a Layered Pane:

    layeredPane = new JLayeredPane();
    getContentPane().add(layeredPane);
    layeredPane.setPreferredSize( boardSize );
    layeredPane.addMouseListener( this );
    layeredPane.addMouseMotionListener( this );

    //  Add a JPanel for the chessboard to the Layered Pane's default layer:

    chessBoard = new JPanel();
    layeredPane.add(chessBoard, JLayeredPane.DEFAULT_LAYER);
    chessBoard.setLayout( new GridLayout(8, 8) );
    chessBoard.setPreferredSize( boardSize );
    chessBoard.setBounds(0, 0, boardSize.width, boardSize.height);

    // Add a Jpanel for each square to the JPanel for the chessboard,
    // white and black depending on calculation:

    for (int i = 0; i < 64; i++) {

        JPanel square = new JPanel( new BorderLayout() );
        chessBoard.add( square );

        int row = (i / 8) % 2;
        if (row == 0)
            square.setBackground( i % 2 == 0 ? Color.white : Color.black );
        else
            square.setBackground( i % 2 == 0 ? Color.black : Color.white );
    }

}

So, from the application's perspective, this is what the board looks like:

However, since the web service sent you 'd7d5', this is how you'd like the application to see the board:

So, you need to convert the start position 'd7' to '11', which is d7's number on the board. Find 'd7' in the lower picture above and then find the number that represents that square in the upper picture: (i) in the upper picture, the lowest number in the column in which d7 is found is d7's column number, (ii) in the upper picture, the lowest number in the row in which d7 is found is d7's row number. In the upper picture, the lowest number in d7's column is 3. So, the column number is 3. In the upper picture, the lowest number in d7's row is 8. So, the row number is 8. So, 3 + 8 equals 11, which is the number on the board where 'd7' is found. Here's the code for all the columns:

if (startposition_letter.startsWith("a"))
    startpos_column_number = 0;
else if (startposition_letter.startsWith("b"))
    startpos_column_number = 1;
else if (startposition_letter.startsWith("c"))
    startpos_column_number = 2;
else if (startposition_letter.startsWith("d"))
    startpos_column_number = 3;
else if (startposition_letter.startsWith("e"))
    startpos_column_number = 4;
else if (startposition_letter.startsWith("f"))
    startpos_column_number = 5;
else if (startposition_letter.startsWith("g"))
    startpos_column_number = 6;
else if (startposition_letter.startsWith("h"))
    startpos_column_number = 7;

Notice how each startpos_column_number above (highlighted in the code above) matches the starting numbers of each column in the upper table. So, A is 0, B is 1, C is 2, etc.

And here's the code for all the rows:

if (startposition_no == 8)
    startpos_row_number = 0;
else if (startposition_no == 7)
    startpos_row_number = 8;
else if (startposition_no == 6)
    startpos_row_number = 16;
else if (startposition_no == 5)
    startpos_row_number = 24;
else if (startposition_no == 4)
    startpos_row_number = 32;
else if (startposition_no == 3)
    startpos_row_number = 40;
else if (startposition_no == 2)
    startpos_row_number = 48;
else if (startposition_no == 1)
    startpos_row_number = 56;

Notice how each startpos_row_number above (highlighted in the code above) matches the starting numbers of each row in the upper table. So, 8 is 0, 7 is 8, 6 is 16, etc.

The exact same procedure is then repeated for the end position (i.e., the 'd5' part of 'd7d5'). And then the piece is moved:

JPanel from = (JPanel)chessBoard.getComponent(startpos_column_number + startpos_row_number);
JLabel chessPiece = (JLabel)from.getComponent(0);
        
JPanel to = (JPanel)chessBoard.getComponent(endpos_column_number + endpos_row_number);
to.add(chessPiece);

from.revalidate();
to.revalidate();
layeredPane.repaint();

All of the above happens when the 'Send FEN' button is clicked. Of course, that button also invokes the actual call on the web service. But, as you can see from the complexity of translating the returned string to something that the application understands, the invocation on the web service is only one really small sub-step within a much larger whole. In other words, thanks to the Web Service Client wizard in NetBeans IDE Dev (which generates all the files and code snippets needed for communicating with the web service), contacting the web service is trivial. In many ways, the web service is nothing more than a glorified database -- because the IDE generates all the code for you, you might as well be using the Choose Database dialog box. And that's really quite wonderful.

The highlight of building this chess client, so far, was the moment when I clicked the 'Send FEN' button and -- two seconds later -- the black chess piece moved across the board by itself, using the string returned from the web service! That was pretty cool. So... now the next move in the building of my chess client is to generate that FEN string myself. Luckily I've been in touch with Valentin Iliescu, the creator of the chess web service and he's given me some really useful pointers.

Aug 24 2005, 01:32:45 AM PDT Permalink

Download NetBeans!

20050823 Tuesday August 23, 2005

A Five-Minute NetBeans Tutorial

I've just finished updating the NetBeans Project Sample Plug-in Tutorial. I basically had to delete 50% of the previous version and replace the text with two screenshots -- because there's now a wizard that does all of the work for you. It's the new Project Template wizard, which makes NetBeans projects available as project samples in the New Project wizard. (By the way, if you want to create a new project template, you could also use this wizard to create its basis. Then you can make the template available in the New Project wizard, in the list with web projects or J2SE projects or one of the other project types.)

When I'd finished updating the tutorial, I realized that there was a sentence at the top that said: "Once the software is installed, this tutorial can be completed in 20 minutes." I browsed through the tutorial and then realized that that was no longer accurate -- you can now literally complete it in 5 minutes... Not bad, huh. And there are several more wizards on the way!

At the bottom of the updated tutorial is a list of open issues, things I need to add or resolve. If you work through the tutorial and have any other questions or issues that you think the tutorial should deal with, please let me know!

Aug 23 2005, 02:40:33 AM PDT Permalink

Download NetBeans!

20050822 Monday August 22, 2005

About that proxy server ... (Part 2)

In yesterday's blog entry I felt all pleased because I'd worked out how to set the proxy host and port number for NetBeans J2SE projects. This is what I did:

  1. Create my.properties file in my application's root directory.
  2. Add proxy host and port number to the my.properties file:

    http.proxyHost:webcache.uk
    http.proxyPort:8080
  3. Right-click the project, choose Properties, click Run, and type my.properties in the Arguments field.
  4. Add this to the project's main class:

     if (args.length != 1) {
       System.err.println("Where's your properties file?");
       System.exit(1);
     }
            
     // Retrieve settings from the properties file,
     // add to system properties
     Properties myprops = new Properties();
     myprops.load(new FileInputStream(args[0]));
            
     Properties props = System.getProperties();
            
     Enumeration propNames = myprops.propertyNames();
     while (propNames.hasMoreElements()) {
        String s = (String) propNames.nextElement();
        props.setProperty(s, myprops.getProperty(s));
     }

However, then I re-read Brian Leonard's Running the Amazon Web Services Sample Application In NetBeans and realized that all I really needed to do (instead of creating the my.properties file, putting it in the project's Arguments field, and adding a whole bunch of code to the main method) was add the proxy host and port number to the project's VM Options field (click to enlarge):

-Dhttp.proxyHost=webcache.uk -Dhttp.proxyPort=8080

Sometimes life is a lot simpler than it seems!

And why is this blog entry called "About that proxy server ...(Part 2)"? Where's Part 1? Well, Gregg wrote that: About that proxy server ... That blog entry looks at the proxy server for web-based clients, while this looks at it from the perspective of a Java application.

Aug 22 2005, 03:04:58 AM PDT Permalink

Download NetBeans!

20050821 Sunday August 21, 2005

Yes! Web Service Support in Java Applications!

Regular readers of this blog know that I've been eagerly awaiting the availability of web service support in NetBeans J2SE projects. The experiments I've done recently in the web service area have all focused on web applications. Yesterday Milan Kuchtiak, currently the main developer in Prague responsible for web service developments, made a big commit to trunk -- exactly what I had been hoping for for a while now -- web service support in the J2SE area. "Now I'll be able to finish my chess game!" I thought. (Actually, I wasn't the only one who thought that -- Roman and Christopher Atlan both wrote me yesterday, telling me about the J2SE commit and urging me to continue work on the chess game!)

But I was to be disappointed. I started out by trying to consume the simplest web service available on the web:

http://www.seshakiran.com/QuoteService/QuotesService.asmx

This web service, discussed earlier in this blog, and also in Consuming Web Services in NetBeans IDE 4.1 (Part 1), is the simplest web service on the web because its operation requires no arguments. All you need to do is invoke an operation on the web service, and then a quotation is returned to the client. So I used the new Web Service Client wizard in the J2SE project. The experience was the same as with web applications -- use the wizard to specify the WSDL URL and the package where the client files will be generated, click Finish and then use the 'Call Web Service Operation' menu item from inside the Java class to generate the code needed to contact the web service. Things were looking good. But then... when I ran the project, I got this java.rmi.RemoteException printed in the IDE's Output window:

java.rmi.RemoteException: HTTP transport error: java.net.UnknownHostException: www.seshakiran.com; nested exception is: 
        HTTP transport error: java.net.UnknownHostException: www.seshakiran.com

This was bad news and I didn't know how to solve it. In web applications, a message like this is caused by being behind a firewall and solved by setting the host and port number on the Sun Java System Application Server. But the J2SE project doesn't use a server! So where do you set the host and port number? I was pretty well stuck, until I remembered that chapter 3 ("SOAP with Attachments API for Java") of the J2EE 1.4 Tutorial for NetBeans IDE 4.1 contains several NetBeans-projectized SOAP samples -- including several J2SE samples. I remembered that these samples, somehow or another, made contact with a web service... so if they could do it, so could mine. The sample that I ended up learning a lot from is called MyUddiPing.java. The host and port number are set in a properties file which is passed as an argument (in the Project Properties dialog box). This is the content of my properties file:

http.proxyHost:webcache.uk
http.proxyPort:8080

The name of the above file is my.properties (but could be called anything with a properties file extension) and that is exactly what I typed in the Arguments field in the project's Run panel (right-click the project in the Projects window to open the Project Properties dialog box and then click the Run panel to find the Arguments field). And this is what I added to the main method of my J2SE project:

 if (args.length != 1) {
   System.err.println("Where's your properties file?");
   System.exit(1);
 }
        
 // Retrieve settings from the properties file,
 // add to system properties
 Properties myprops = new Properties();
 myprops.load(new FileInputStream(args[0]));
        
 Properties props = System.getProperties();
        
 Enumeration propNames = myprops.propertyNames();
 while (propNames.hasMoreElements()) {
    String s = (String) propNames.nextElement();
    props.setProperty(s, myprops.getProperty(s));
 }

(By the way, to use the above code, you'll find you need to import java.util.Properties and throw FileNotFoundException and IOException.)

Great, so now everything worked! I was able to contact the quotation web service and invoke its operation -- and here's the evidence:

Next I dug up an e-mail from Gregg Sporar from some time ago. He'd read my blog entry Unjumble That Anagram! and wrote: "Have you by chance looked at the latest dev. build to see how the support for calling web services from a J2SE app is coming? I haven't had time to look at it, but I'd like to add a "Cheat" button to the Anagram app!" That's a great idea -- and so I implemented it. (There were two big problems, though -- under Windows you get an NPE after using the 'Call Web Service Operation' menu item and you have to fiddle around with the project to make it conform to the new web-service style of J2SE projects.) Here's what the Anagram game (you can get the boring non-cheat version from the New Project wizard's Samples/General category) looks like now (the 'guessed word' below was generated when I clicked the 'Cheat' button -- i.e., I didn't type anything, it was all done by the web service):

Apart from adding the host and port number via a properties file, as described above, I turned the J2SE project into a client using the Web Service Client wizard (with this web service), added a Cheat button and this ActionPerformed method (the emboldened line is the invocation on the web service):

private void cheatButtonActionPerformed(java.awt.event.ActionEvent evt) {
        
  String anagram = scrambledWord.getText();
  int no_of_letters = anagram.length();
        
  try {
      com.toy.anagrams.ui.CountCheatService countCheatService = new com.toy.anagrams.ui.CountCheatService_Impl();
      com.toy.anagrams.ui.CountCheatServiceSoap countCheatServiceSoap = countCheatService.getCountCheatServiceSoap();
      String[] s = countCheatServiceSoap.letterSolutionsMin(anagram,number).getString();
            
      if (s.length > 0) {
         for (int i = 0; i < s.length; i++) {
            guessedWord.setText(s[i]);
         }
         guessedWordActionPerformed(evt);
      } else {
         feedbackLabel.setText("Sorry... word not recognized!");
      }

  } catch(javax.xml.rpc.ServiceException ex) {
     System.out.println(ex);
  } catch(java.rmi.RemoteException ex) {
     System.out.println(ex);
  }
       
}

And now... I better start looking at that chess game! I already know what the problem's going to be -- how to turn a move on the chessboard into one of those tricky FEN strings... But, from the perspective of communicating with the web service (once I know what to communicate to it), thanks to the new web service support for J2SE projects, it's going to be a piece of cake!

Aug 21 2005, 03:12:04 AM PDT Permalink

Download NetBeans!

20050820 Saturday August 20, 2005

Being Greedy: Instantaneous Struts and JSF Support in NetBeans IDE

When I wrote How to setup a basic Struts project using NetBeans IDE 4.0, I was quite amazed at how much smoother Struts integration had become since NetBeans 3.4. I mean, of course I expected improvements and so on, but I didn't realize, until writing the article, the extent to which Struts support in NetBeans had advanced. NetBeans IDE 4.1 stayed the same for Struts -- no changes were made. But the next release is going to provide a problem though -- Struts (and JSF) will be so tightly integrated in the IDE that there won't be many ways to improve any further after that! On the bright side, my rewrite of that Struts article for the next release is going to be very very simple. It's going to consist of four screenshots, each accompanied by one sentence. Here's the draft... it covers Struts and JSF.

Creating a New Project with Struts and JSF Support

Use the new 'Frameworks' panel in the New Project wizard (click to enlarge):

Adding Struts and JSF Support to an Existing Project

Use the new 'Frameworks' panel in the Project Properties dialog box (click to enlarge):

Let's assume you're greedy -- you chose both Struts and JSF. What does your project look like? Well, click the screenshot below to find out...

And what about code completion? Straight out of the box, without configuring anything anywhere, click Ctrl-Space in the Source Editor, et voila (click to enlarge):

By the way, note the new code snippet panel -- cool, isn't it?

Aug 20 2005, 08:33:13 AM PDT Permalink

Download NetBeans!

20050819 Friday August 19, 2005

Unleash the Power of Web Services!

They're drafts, but they're pretty solid nonetheless... two new tutorials that explain (step-by-step, including code and a downloadable sample) how to consume web services. Part 1 is very simple -- little more than a quick start guide. Part 2 goes into a lot more detail, looks at a lot of the nuts and bolts (but only as far as you need to know about them) and leaves you with a friendly front-end that interacts with a spellcheck web service.

Consuming Web Services in NetBeans IDE 4.1 (Part 1)

Consuming Web Services in NetBeans IDE 4.1 (Part 2)

Yes, if you're familiar with Eating Web Services in NetBeans IDE 4.1, then both the above draft tutorials will look very familiar to you! However, the tutorials have a lot of additional info, together with a downloadable sample and easy to follow steps. Thanks to John, Gregg and Lukas for their feedback on that blog entry.

Although both tutorials are works in progress, any feedback would be very highly appreciated!

Aug 19 2005, 07:58:39 AM PDT Permalink

Download NetBeans!

20050818 Thursday August 18, 2005

If Shakespeare Spoke Pig Latin...

...this is an example of what he would've written:

Two web services are involved in creating the above output -- a web service that retrieves Shakespeare quotations (WSDL) and a web service that translates from English to Pig Latin (WSDL). I used NetBeans IDE 4.1 to consume the web services, which means that my complete ignorance of SOAP was not an obstacle -- a wizard did most of the work and all I had to do was add some code to process the data returned from the web services.

I find it a little bit disconcerting that, after digging through a lot of web services, I can say with a reasonable degree of confidence that the only reliable web service that translates English into any other language is one that translates it into Pig Latin. How bizarre! All other -- without a single exception -- translation web services just don't work.

By the way, if you're interested in getting comfortable with web services, but are asking yourself "Where should I go to find some cool web services to play with?", you should take a look at the following on-line resources (especially the first one, it's a gold mine):

Aug 18 2005, 12:12:53 AM PDT Permalink

Download NetBeans!

20050817 Wednesday August 17, 2005

Generate Your Own Code Completion in NetBeans IDE

Something I discovered yesterday is how easy it is to add code completion functionality to any XML file. Say, for example, you work a lot with datasource configuration files for JBoss. It's really easy to set things up so that, while typing, a little drop-down such as the following appears to suggest tags to use:

To create that list, all you need is a DTD file. Code completion for XML files is based on the DTD file declared in the second line of the XML file. But, there's more: you can use the IDE to generate your DTD file, using the XML file as its basis. So, right-click inside the Source Editor while the XML file that contains the tags you need is open. Then choose Generate DTD. Once you've generated the DTD file, you need to add the DTD declaration to the top of any XML file that should use the DTD file. For example, here's my DTD declaration for Pointbase datasource configuration files in JBoss:

<!DOCTYPE datasources PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "pointbase-ds.dtd">

That's all I had to do -- then, thanks to the DTD file, code completion is available for any JBoss datasource configuration file that references my DTD file. (There are several open issues in this area. The one that tripped me up is that you need to manually save a file before generating the DTD. This is because the DTD is generated based on the saved version, and no autosave is currently carried out.) I've done the same thing for the Shakespeare files that I've been retrieving from the Shakespeare web service that I discussed in some recent blog entries:

By the way, something else I've discovered is how to read XML files. Previously, I'd written the retrieved Shakespeare string to an XML file. However, what if I don't want to display the whole retrieved string, but only part thereof -- for example, only the play or the speaker? My user interface would be something like this:

To implement this, I needed to read the returned XML string. I knew what was being returned, i.e., the tags were known to me, so based on that I identifed the tags and assigned their content to a string. So, this is what I added to the servlet to make it possible to identify the play and the speaker from the returned Shakespeare quotation (the code snippet below starts with the invocation on the getSpeech operation, which is made available by the web service):

String s = getShakespeareSoap().getSpeech(quotation);
        
String startPlayTag = "<PLAY>";
String endPlayTag = "</PLAY>";
int startPlay = s.indexOf(startPlayTag) + startPlayTag.length();
int endPlay = s.indexOf(endPlayTag);
String play = s.substring(startPlay, endPlay);
        
String startSpeakerTag = "<SPEAKER>";
String endSpeakerTag = "</SPEAKER>";
int startSpeaker = s.indexOf(startSpeakerTag) + startSpeakerTag.length();
int endSpeaker = s.indexOf(endSpeakerTag);
String speaker = s.substring(startSpeaker, endSpeaker);

Aug 17 2005, 02:34:21 AM PDT Permalink

Download NetBeans!

20050816 Tuesday August 16, 2005

Drag-and-Drop JSP and HTML Code Snippets in NetBeans IDE

Check out the cool palette that makes my JSP and HTML life so much easier. I found it in a NetBeans IDE Dev build yesterday, (i.e., it is not in NetBeans IDE 4.1, but in a development build for the next release, which you can download and try out here). The palette opens automatically when you open a JSP file or an HTML file in the Source Editor. Then you drag the code snippet of your choice into the page. Next, a dialog box opens and you can define the most common properties. Really good news, I think. This is what it looks like for a button:

Aug 16 2005, 01:31:04 AM PDT Permalink