The divas talk about the new and cool features of the NetBeans IDE
Insider Scoop From the Tutorial Divas
Archives
« August 2007 »
SunMonTueWedThuFriSat
   
1
2
3
4
5
6
7
8
11
12
13
15
18
19
20
22
23
24
25
26
27
28
30
 
       
Today
XML
Search



Recent Entries


Links

 


Today's Page Hits: 953

Tag Cloud: ajax creator dataprovider dropdown glassfish jasperreports javaone jmaki jruby jsc jsf netbeans photohunt rails ruby table vwp
« Previous month (Jul 2007) | Main | Next month (Sep 2007) »
Friday Aug 31, 2007
Publishing Now Belongs to the Community

Just watched this interesting video which pretty much sums up my 10 years at Sun.

At first I wrote "man" pages and hard-copy manuals that were published once a year. By the time they came out, they were already obsolete. I never knew if anyone read my stuff or if it met their needs. We eventually started writing technical articles in HTML, but these were not published until the official release. Any errors or updates could not be corrected until the next release. In the past few years, we have been publishing our tutorials on the web as soon as we write them and updating them whenever necessary. We put feedback buttons on the page so people could report errors or make suggestions. We wrote back and often started dialogs. We requested tutorial suggestions and got lots of input. Then we started this blog and started pushing out information as soon as we learned it, so that people didn't have to wait until we had put it in some polished tutorial. Now we have joined the NetBeans Ruby team and our roles have totally changed. We are no longer a group of writers who take information from the engineers and make it available to the software users, we are members of a community of contributors to the NetBeans Ruby Wiki. When I have questions about the topic I am working on, I don't just turn to the engineers, I turn to the community. They help me write my docs, and hopefully, I can help them write theirs. These are exciting times.

Posted at 01:19PM Aug 31, 2007 in Ruby  |  http://blogs.sun.com/divas/entry/publishing_now_belongs_to_the  |  Permalink  |  Comments[2]
del.icio.us | furl | simpy | slashdot | technorati | digg

New Video on Java and Ruby Development

Check out the new video on NetBeans TV titled Mixing Java and Ruby Development. In this video, Ruby developer Tor Norbye uses NetBeans IDE 6.0 to integrate a Java CRUD application with a Ruby on Rails application. The video highlights many of the features of the NetBeans Ruby editor, including code completion. Also included are the Rails code generator and the IDE's JUnit module.

Our coworker, Cindy Church, put in long hours producing the video and it shows in the content and quality of the video. The video is fairly fast-paced, so a written version of the video script is also available.

Posted at 10:04AM Aug 31, 2007 in Ruby  |  http://blogs.sun.com/divas/entry/new_video_on_mixing_java  |  Permalink  |  Comments[1]
del.icio.us | furl | simpy | slashdot | technorati | digg

Wednesday Aug 29, 2007
Opening a File From the Command Line

I learned a neat trick in the dev@ruby.netbeans.org mailing list this week, one that I wish I had discovered long ago -- how to open a file in the Netbeans editing area from the command line, even if the file is not in an opened project.

Make sure that the NetBeans bin directory is in your path. Then use the following command to open the file in the NetBeans editing area.

netbeans --open file

Even better, make an alias:

alias nb='netbeans --open '

Then you can simply type nb file. The command will start up the NetBeans IDE if necessary. If the IDE is already open, the command simply opens the file and pops it to the front of the editing area.

If you are using Windows, you can also do the following to open a file in the IDE.

  1. Right-click on a file in an explorer window.
  2. Choose Open With > Choose Program.
  3. Select NetBeans from the program list. If NetBeans is not on the program list, click Browse, navigate to and select netbeans-install-dir/bin/netbeans.exe, and click open.
  4. Click OK. The file opens in the IDE. Sometimes the IDE does not show the file's tab right away so it looks like the file has a different name. If you hover over another tab, the file's tab usually appears.

For more information, see wiki.netbeans.org/wiki/view/FaqCliOpen

Posted at 11:27AM Aug 29, 2007 in Ruby  |  http://blogs.sun.com/divas/entry/opening_a_file_from_the  |  Permalink  |  Comments[1]
del.icio.us | furl | simpy | slashdot | technorati | digg

Tuesday Aug 21, 2007
Relatively Positioning Web UI Components
Tip on positioning Web UI components based on the width of the browser window in a NetBeans Visual Web Application or a Sun Java Studio Creator Application.[Read More]
Posted at 01:41PM Aug 21, 2007 in Web UI Components  |  http://blogs.sun.com/divas/entry/relatively_positioning_web_ui_components  |  Permalink  | 

Friday Aug 17, 2007
Check Out the NetBeans Ruby Wiki

Gail has been very busy this week working on the docs pages at the NetBeans Ruby Wiki Check it out and let us know what you think. This is a community site, so if you have stuff to contribute, the instructions are there.

At the bottom of the main page is a link to Documents Under Construction. I have the honor of listing the first draft to be offered up for review, "Installing and Configuring Ruby Support in the NetBeans IDE." This is a very raw draft, as I am still in the learning and exploring phase of information gathering. I thought it would be good to get this out so we can get feedback on what kind of information you really need during your initial use of the Ruby Support Package.

A lot of the stuff we put in here was due to the suggestions you have sent us so far. I also want to give Tor, Brian, Arun and other developers a big applause for providing most of the information that I added to this draft through their blogs and their wiki contributions.

Posted at 07:55PM Aug 17, 2007 in Ruby  |  http://blogs.sun.com/divas/entry/check_out_the_netbeans_ruby  |  Permalink  | 

Thursday Aug 16, 2007
SqlException: At least one parameter to the current statement is uninitialized

When you do the Using Databound Components to Access a Database tutorial, you learn how to use the Query Editor on the rowset to build the SQL statement to retrieve the desired set of data. You also learn that for every ? (parameter) in your query, you need to call setObject() on the rowset before the query is executed. Take, for example, the following query.

SELECT ALL TRAVEL.TRIP.TRIPID, 
           TRAVEL.TRIP.PERSONID, 
           TRAVEL.TRIP.DEPDATE 
FROM TRAVEL.TRIP
WHERE TRAVEL.TRIP.PERSONID = ?
   AND TRAVEL.TRIP.TRIPTYPEID = ? 
This query has two parameters, PERSONID and TRIPTYPEID. What this means is that you have to provide values for these two parameters before the rendering phase. You typically do this in the prerender() method, as shown in the following code example.
public void prerender() {
    if ( personIdDD.getSelected() == null ) {
        try {
          personDataProvider.cursorFirst();
          getSessionBean1().getTripRowSet().setObject(
            1, personDataProvider.getValue("PERSON.PERSONID"));
          getSessionBean1().getTripRowSet().setObject(
            2, "4");
          tripDataProvider.refresh();
        } catch (Exception e) {
          error("Cannot switch to person " +
              personDataProvider.getValue("PERSON.PERSONID"));
            log("Cannot switch to person " +
              personDataProvider.getValue("PERSON.PERSONID"), e);
        }
    }
}

If you forget to set the parameters before the rendering phase, you usually get the following error.

SqlException: At least one parameter to the current statement is uninitialized.

You will also get an error like this if you do not set all the parameters. Such as only calling setObject(1, somevalue) when you have two parameters in the query.

Another common error is to forget to edit the query to add the parameters. If you call setObject(1, somevalue), but your query has no parameters (no ?), you might get an error like the following.
java.lang.NullPointerException
at org.apache.derby.client.am.PreparedStatement.checkForValidParameterIndex(Unknown Source)

Similarly, if you call setObject(2, somevalue) when your query has only one parameter, the server will emit something like the following message.
SqlException: The parameter position '2' is out of range.  
The number of parameters for this prepared  statement is '1'

Posted at 06:01PM Aug 16, 2007 in Web UI Components  |  http://blogs.sun.com/divas/entry/sqlexception_at_least_one_parameter  |  Permalink  |  Comments[7]
del.icio.us | furl | simpy | slashdot | technorati | digg

Tuesday Aug 14, 2007
Three Girls in a Row
Posted at 11:43AM Aug 14, 2007 in Personal  |  http://blogs.sun.com/divas/entry/three_girls_in_a_row  |  Permalink  |  Comments[3]
del.icio.us | furl | simpy | slashdot | technorati | digg

Friday Aug 10, 2007
jMaki 0.9.7: Using the Yahoo Tabbed View in a NetBeans Visual Web Application

Yesterday, in our blog entry about using the Spry Accordion widget, we mentioned that it uses the same data model as the tabbed view and that you would swap out widgets. Today I will show you how simple it is to do so.

First, complete the steps from yesterday's mini-tutorial.

Next, open your Base jMaki project, and drag a Yahoo Tabbed View widget into index.jsp. Run the project to ensure that all the necessary files are copied into the  resources/yahoo folder.

Copy the resources/yahoo folder from the Base jMaki project and paste it into the resources folder of your Visual Web project.

Click JSP to view the JSP tags for Page1. Replace the following line:

<a:widget name="spry.accordion" value="#{SessionBean1.tripContent}"/>

with:

<a:widget name="yahoo.tabbedview"
  value="#{SessionBean1.tripContent}" />

Now click the Run Main Project button. You should see a tabbed view instead of the accordion.

Posted at 10:23AM Aug 10, 2007 in AJAX  |  http://blogs.sun.com/divas/entry/jmaki_9_7_using_the  |  Permalink  |  Comments[2]
del.icio.us | furl | simpy | slashdot | technorati | digg

Thursday Aug 09, 2007
Using the Spry Accordion in a Visual Web Application With jMaki 0.9.7

The jMaki team keeps making great changes to the technology, but sometimes it is hard to keep up with all the changes. I have finally gotten a working version of the latest jMaki-wrapped Spry Accordion. I think that this API will be stable for awhile, so now is a good time to post some instructions on how to use the Spry Accordion in a NetBeans 5.5.1 Visual Web project using the latest NetBeans jMaki plug-in (1.6.9.9.9.5), which bundles jMaki 0.9.7.

One of the recent changes has been the data model. The jMaki team is now publishing the data model information on the ajax.dev.java.net portal at http://wiki.java.net/bin/view/Projects/jMakiDataModels. The data model for the Spry Accordion widget is as follows:

    items::= "{"  {<label> } "}"
    label ::=  "{" "label:"  <string>, [<content> | <include> |<action> ] 
       [<lazyload>]  [<rowid>] <selected>"},"
    selected ::= "selected:" "true" | "false"  (default is false)
    include ::= "include:" <string> ,  
    lazyload ::= "lazyload:" "true" | "false",
    rowid ::= "rowid:" <string> ,
    content ::= "content:" <string>,
    action ::= "action:" "{" [<topic>] <message>  "},"
    topic ::=  "topic:" <string>,
    message ::= "message:" <obj>
    obj ::= <string> | <JavaScript object literal>

Note: This model is the same as the data model for the tabbed view. This means that you can swap out the accordion with a tabbed view and not have to change the data.

To follow this mini-tutorial, you need to get the NetBeans jMaki Plugin. If you have already installed the plugin, use the NetBeans Update Center from the Tools menu to make sure you have the latest version (1.6.9.9.9.5). If you have an earlier version, See Carla's blog entry about how to update the jMaki framework resources in a jMaki project.

I noted in an earlier blog entry that you also need to download the JSF Compounds library (jsfcompounds-0.0.2.jar). This is no longer true. The 1.6.9.9.9.5 plug-in includes this library.

  1. Create a plain (not a Visual Web) Web Application project, name the project something like BaseJSFjMaki097, choose the Sun Java Application Server, and click Next. Select jMaki Ajax Framework and select JavaServer Faces, then click Finish (honestly, for the purposes of this tutorial, it doesn't really matter if you include the JSF framework or not. It works either way). You now have a project from which you can copy the necessary jMaki resources into your Visual Web Project.

  2. Drag the jMaki Spry Accordion widget from the Palette into the index.jsp to add the the widget's resources to the project.

  3. (Important) Click the Run Main Project button. I have noticed that not all the widget resource library files get copied into the project until you run the project. We need to make sure we have them all before we copy them into our VWP project.

  4. Now, create a new Visual Web Project and make it the main project.

  5. To add the jMaki libraries (ajax-wrapper-comp, org.json, and jsfcompounds) to your project, right-click the Libraries node and choose Add Library. Choose jmakilibrary from the Library Manager (when you installed the plugin, it put the jmakilibrary into the Library Manager) and click OK.

  6. Copy the supporting files from the BaseJSFjMaki project to your project:

    1. Copy BaseJSFjMaki/Web Pages/glue.js to Your-VWP-Project/Web Pages.

    2. Copy the following files from BaseJSFjMaki/Web Pages/resources to Your-VWP-Project/Web Pages/resources:

      • config.json
      • jmaki.js
      • system-glue.js


    3. Copy the BaseJSFjMaki/Web Pages/resources/spry folder to Your-VWP-Project/Web Pages/resources.

  7. You can now close the BaseJSFjMaki project.

  8. In the Visual Designer add a Group Panel component to the page (Page1). You will be putting the accordion in this component. This enables you to position the ajax widget as well as see in the visual designer where this jMaki widget is. Any of the layout components will suffice, but for this tutorial, I chose to use the Group Panel.

  9. In the IDE, click the JSP button in the editing toolbar to display the JSP tags for the page.

  10. Add xmlns:a="http://jmaki/v1.0/jsf" to the <jsp:root> tag.

  11. Replace the <webuijsf:panelGroup> tag with the following tags:
    <webuijsf:panelGroup binding="#{Page1.groupPanel1}" id="groupPanel1"
      style="position: absolute; left: 72px; top: 48px;">
       <a:widget name="spry.accordion" value="#{SessionBean1.tripContent}"/>
    </webuijsf:panelGroup>

Now we can setup the web application to return data from the Travel database in the data model format for the accordion.

  1. Click Design to display Page1 in the Visual Designer. This also causes the Navigator window to appear, which you will need in Step 5.

  2. Click the Runtime tab to display the Runtime window.

  3. In the Runtime window,  expand databases , right-click the jdbc:derby node for the travel database, and choose connect. If prompted, type travel in the Password text box and click OK. (The sample travel database is installed if the Sun Java Application Server was added to the IDE before you installed the Visual Web Pack. If you do not see the travel database, go to the NetBeans Visual Web Pack Installation Instructions for information about installing the sample travel database.)

  4. Expand the jdbc:derby node for the travel database, and expand the Tables node.

  5. Drag the TRIP node from the Runtime window and drop it on the SessionBean1 node in the Navigator window, as shown in the following screen shot.



  6. When you dropped the TRIP table on the SessionBean1 node, the IDE added a tripDataProvider node and a tripRowSet node. Double-click the tripRowSet node to open its query in the query editor.

  7. Replace the query in the Query pane (the third pane down) with the following query.
    SELECT ALL TRAVEL.PERSON.PERSONID, 
      TRAVEL.PERSON.NAME, 
      TRAVEL.TRIP.TRIPID, 
      TRAVEL.TRIP.DEPDATE 
    FROM TRAVEL.PERSON
      INNER JOIN TRAVEL.TRIP ON TRAVEL.TRIP.PERSONID = 
        TRAVEL.PERSON.PERSONID
    ORDER BY TRAVEL.PERSON.PERSONID ASC, 
      TRAVEL.TRIP.DEPDATE ASC 
    


  8. Right-click in the query pane and choose Parse Query. The query editor updates the other panes to match the query.

  9. Close the query editor.

  10. Click the Projects tab to display the Projects window.

  11. In the Projects window, double-click the Session Bean node to open the source for SessionBean1.

  12. Add the following code to the bottom of the source, just before the ending brace (}).
         public String getTripContent() {
            // Data Model Format
            // { items : [
            //   {label: "label", content : "content"},
            //   ...
            //  ]}
            String retVal = "";
            try {
                retVal = buildTripTreeData().toString();
            } catch (JSONException ex) {
                log("Exception building tree data" +
                        ex.getMessage());
            }
            return retVal;
        }
        
        
        public JSONObject buildTripTreeData()
        throws JSONException {
            JSONObject rootObject = new JSONObject();
            JSONArray items = new JSONArray();
            JSONObject itemObject = new JSONObject();
            boolean hasNext = tripDataProvider.cursorFirst();
            Integer currentPersonId =
                    (Integer) tripDataProvider.getValue(
                    "PERSON.PERSONID");
            String currentName = 
                    tripDataProvider.getValue(
                    "PERSON.NAME").toString();
            StringBuffer currentContent = new StringBuffer();
            while (hasNext) {
                Integer newPersonId =
                        (Integer) tripDataProvider.getValue(
                        "PERSON.PERSONID");
                if (!newPersonId.equals(currentPersonId)) {
                    // write out data for previous person
                    itemObject.put("label", currentName);
                    itemObject.put("content", 
                      currentContent.toString());
                    items.put(itemObject);
                    // start gathering data for a new item
                    currentPersonId = newPersonId;
                    currentName = 
                            tripDataProvider.getValue(
                            "PERSON.NAME").toString();
                    itemObject = new JSONObject();
                    currentContent = new StringBuffer();
                }
                // Add trip's date to the content
                currentContent.append(tripDataProvider.getValue(
                        "TRIP.DEPDATE").toString() +
                        "<br>");
                hasNext = tripDataProvider.cursorNext();
            }
            // write out data for last person
            itemObject.put("label", currentName);
            itemObject.put("content", currentContent.toString());
            items.put(itemObject);
            rootObject.put("items", items);
            return rootObject;
        }
    

    Note: I got the idea for the buildTripTreeData method from Watsh Rajneesh;s Working With jMaki post.

  13. Click the Run Main Project button to run the web application. You should see a panel for each employee, and each panel should contain the dates of that employee's trips. One odd thing happens, though, that I don't now how to fix. Everytime I click a panel header, the accordion gets wider. Does anyone know why that happens?

Greg and Carla say that they have added some cool features to the accordion widget. I am hoping that as I learn about them, I can add to this mini-tutorial.

Posted at 09:31AM Aug 09, 2007 in AJAX  |  http://blogs.sun.com/divas/entry/using_the_spry_accordion_in  |  Permalink  |  Comments[8]
del.icio.us | furl | simpy | slashdot | technorati | digg