The Source for Java Technology Collaboration
User: Password:



Brian Leonard's Blog

September 2005 Archives


More Easy JSTL

Posted by bleonard on September 30, 2005 at 11:34 AM | Permalink | Comments (0)

Yesterday I put together a blog showing how easy it is to work with JSTL in NetBeans. One thankful reader asked for a follow-up on using the JSTL XML library. I think this was primarily due to a problem he was having with a package name change from JDK1.4 to 5 (see my response for more details). But it's simple enough, so here goes anyhow. I'll basically just do what I did yesterday, display a table of customers. However, today, that customer list will come from and XML document rather than a SQL database.

<?xml version="1.0" encoding="UTF-8"?>
<customers>
    <customer>
        <num>1</num>
        <name>SuperCom</name>
        <city>Miami</city>
        <phone>305-777-4632</phone>
    </customer>
    <customer>
        <num>2</num>
        <name>Livingston Enterprises</name>
        <city>Miami</city>
        <phone>305-456-8888</phone>
    </customer>
    <customer>
        <num>25</num>
        <name>Oak Computers</name>
        <city>Dallas</city>
        <phone>214-999-1234</phone>
    </customer>
    <customer>
        <num>3</num>
        <name>MicroApple</name>
        <city>Atlanta</city>
        <phone>555-275-9900</phone>
    </customer> 
 </customers>

I didn't mention yesterday, but this exercise was done with NetBeans 4.1. You could also use the NetBeans 5.0 BETA .

  1. Start NetBeans
  2. Create a new Web Application named CustomerListXML (File > New Project > Web > Web Application)
  3. Add the JSTL library to the project (Properties > Libraries > Add Library)
  4. Uncomment the <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> line in index.jsp
  5. Add the line <%@taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x"%>
  6. Insert the following between the <body> tags:
 <h1>Customer List</h1>
   
 <!-- Parse the XML Customer List -->
 <c:import url="customers.xml" var="xml"/>
 <x:parse xml="${xml}" var="customers"/> 
 
 <TABLE border=1>
     <TR>
         <TD>Customer Num</TD>
         <TD>Customer Name</TD>
         <TD>Customer City</TD>
         <TD>Customer Phone</TD>
     </TR>
     <x:forEach select="$customers/customers/customer" var="customers">
         <TR>
             <TD><x:out select="num"/></TD>
             <TD><x:out select="name"/></TD>
             <TD><x:out select="city"/></TD>
             <TD><x:out select="phone"/></TD>
         </TR>
     </x:forEach>
 </TABLE> 
  1. If you actually took the time to type in the code, you should have noticed the very helpful JSTL code assistance and documentation:

    jstldoc.PNG
  2. If you pasted in the code from above, Press Ctrl+Shift+F to reformat the code.
  3. Add a new Well-formed XML Document named "customers" to the Web Pages folder (New > File/Folder > XML Documents) and replace the contents with the XML from above.
  4. Now, if you're developing on JDK 1.4 OR using the J2EE 1.4 RI (Sun Java System Application Server 8.1) as your runtime, press F6 to test your application. If you're developing on JDK 5.0 AND running on Tomcat, you also need to add xalan.jar to your project (Project > Libraries > Add JAR/Folder) before pressing F6 to run it.

    result-xml.png


NetBeans - Take 2 and Call Me in the Morning

Posted by bleonard on September 29, 2005 at 06:36 PM | Permalink | Comments (4)

I came across this post from a frustrated developer today, and couldn't help but wonder - are we keeping NetBeans a secret? Poor Dan is just trying to create a simple JSP. For some reason, I couldn't see the code referenced in his post, but I think I got the gist of what he's trying to do. Let's tackle them one frustration at a time:

Frustration #1 - Create a Hello World Web Project

  1. Create a new Web Application named HelloWorld (File > New Project > Web > Web Application).
  2. Change the text in index.jsp from "JSP Page" to "Hello World!".
  3. Press F6.

Frustration #2 - Closing and Opening a Project

  1. Choose File > Close "HelloWorld"
  2. Choose File > Open Recent Project > HelloWorld

Frustration #3 - Working with JSTL

Here's where I couldn't see Dan's code. However, it looks like he's just trying to display some results from a table. For the purposes of this example, I'm just going to use the Pointbase database and sample data that comes with the J2EE 1.4 SDK. If you already have a different database set up, just change the settings to match your configuration.

  1. Add the Pointbase JDBC driver to the project (Properties > Libraries > Add JAR/Folder). It's in pbembedded.jar, which you'll find in the J2EE SDK's pointbase/lib directory. For me it's at C:\Sun\Appserver\pointbase\lib\pbembedded.jar.
  2. Add the JSTL library to the project (Properties > Libraries > Add Library)
  3. Uncomment the <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> line in index.jsp
  4. Add the line <%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
  5. Add the following between the <body> tags:
<h1>Customer List</h1>
   
 <sql:setDataSource
 var="customerDS"
 driver="com.pointbase.jdbc.jdbcUniversalDriver"
 url="jdbc:pointbase:server://localhost:9092/sample"
 user="pbpublic"
 password="pbpublic"
 />
 
 <sql:query var="customerQuery" dataSource="${customerDS}">
 SELECT * FROM CUSTOMER_TBL
 </sql:query>
 
 <TABLE border=1>
     <TR>
         <TD>Customer Num</TD>
         <TD>Customer Name</TD>
         <TD>Customer City</TD>
         <TD>Customer Phone</TD>
     </TR>
     <c:forEach var="row" items="${customerQuery.rows}">
         <TR>
             <TD><c:out value='${row.CUSTOMER_NUM}'/></TD>
             <TD><c:out value='${row.NAME}'/></TD>
             <TD><c:out value='${row.CITY}'/></TD>
             <TD><c:out value='${row.PHONE}'/></TD>
         </TR>
     </c:forEach>
 </TABLE>    
    
  1. Press Ctrl+Shift+F to reformat the code.
  2. Start Pointbase (Tools > Pointbase Database > Start Local Pointbase Database). Note, you need to have the J2EE 1.4 SDK added as a server to see this option (Tools > Server Manager > Add Server)
  3. Press F6.
result.png

Headache cured.

Out With The New, In With The Newer

Posted by bleonard on September 28, 2005 at 08:48 AM | Permalink | Comments (2)

One big difference between the application server project and the NetBeans project is how often we release. The application server release schedule is basically driven by the JCP, which pumps out a new J2EE spec every couple of years, at best. With NetBeans, we target roughly a 6-9 month release schedule. The upshot - we get many more release parties than my friends on the application server team.

Well, let's not jump the gun. It's not time to celebrate yet, at least officially. For me, however, it is time to upgrade my default IDE from NetBeans 4.1 to 5.0. That's because today, NetBeans 5.0 Beta hit the streets. That's when the quality's good enough to make it my default IDE. I've been waiting for this date to take advantage of all the good things coming in NetBeans 5.0.

What's my favorite new feature? Well, certainly Matisse revolutionizes Swing development. And with 5.0, I'm looking forward to making my J2SE applications web service clients. I'm also looking forward to using the revamped version control. Actually, one of the reasons I've used the 5.0 development builds was specifically for its built-in ssh client, which makes downloading projects from sites like java.net a snap. However, one feature which just caught my attention, I think I like the most. It's the automatic inclusion of imports when I use code completion. For example, in the Java editor, type "Big" and hit ctrl-space. You'll see the following:

codecompletion.PNG

Nothing new there (except the redundant class name that has been removed from the package indicator). However, when you select either BigDecimal or BigInteger, the import statement for that class is automatically added for you. Fix Imports added to 4.0 was an improvement, but I've still always hated the need to use it. It's this type of attention to detail that makes developers happiest. Check out NetBeans 5.0 and find your favorite new feature. It may surprise you.

 



Professor for a Day

Posted by bleonard on September 20, 2005 at 04:45 PM | Permalink | Comments (0)

Last month at LinuxWorld San Francisco I had the good fortune to meet Leigh Jin - Assistant Professor of Information Systems at San Francisco State University. I say good fortune because I got to do something I love to do, which is speak to university students. You see, I hope my last job title in life is also "Professor".

Anyhow, I believe Professor Jin's opening line to me was: "I've been hearing good things about NetBeans lately". Which, of course, is no surprise to me anymore. Leigh then followed with: "I'm considering using it to teach my Java courses this semester". Great!

As a show of support, I offered to come and give the professor's class an overview of the IDE. All 3 of Leigh's Java classes meet on Tuesdays, so we picked the 6th of September for my presentations.

When I arrived on the 6th, it was evident Leigh had been spending some time with NetBeans, my first clue being the NetBeans Field Guide sitting on her desk. She had also worked her way through the Quick Start Guides linked to from our Welcome Screen.

As I thought about my audience and put together the presentation, I ended up talking about the history of Java, Sun and Free Open Source Software as well as NetBeans. It was strange to be in front of an audience that had never heard of James Gosling, or who's understanding of an IDE was the hard drive interface.

From what I hear, the presentation was well received. I believe the NetBeans feature that resonated most with the students was developer collaboration. Hopefully by now most of them have set up their free accounts and are collaborating with one another to foster their understanding of the language.

The presentation to SFSU has spawned a similar presentation at San Jose State University in early October. And hopefully that presentation will lead to others. However, now that word of this presentation has hit the blogoshpere, let me know if you'd be interested in having me come to your school as well. I enjoy getting to play professor for a day.





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds