Welcome!

Java IoT Authors: Pat Romanski, Liz McMillan, Yeshim Deniz, Elizabeth White, Carmen Gonzalez

Related Topics: Java IoT

Java IoT: Article

Taking a Sun Java Studio Creator for a Drive

Taking a Sun Java Studio Creator for a Drive

If you do not really enjoy the process of creation of Web applications with JavaServer Pages, try Sun Java Studio Creator (JSC), which at the time of this writing is available as an Early Access release. There are several general reviews of this product on the Internet, but I'll show you how in less than an hour you can create a Web application with a logon page that performs database user authentication, and displays the main application page for a valid user. If this does not impress you, I can add that I had to write not more than 20 lines of code for this application - the rest was drag and drop.

First, download and install an Early Access release of JSC from wwws.sun.com/software/products/jscreator/ . Installation process is simple, and the product comes with Sun Application Server and PointBase DBMS.

Getting Familiar with IDE
After installation is done, start JSC and create a new project called TestLogon by selecting menus File | New Project. In several seconds, you'll see the windows that looks like this:

 

The big white rectangle in the middle is a page editing area, and we'll be dragging and dropping JSP Standard components from Pallete to the editing area. Right-click in the middle, select Properties and you'll see the Properties sheet in the top right part of the screen. The tabs at the bottom of the editing area allow you to switch between design and JSP source code panels.

The Project Navigator sheet on the right will let you select generated Java code for compilation, editing and debugging. There you can also specify page navigation for your application and add additional jar files, if needed.

Our first Page1.jsp will consist of three output text components (labels), two text fields and a Submit button.

Drag and drop the output text component on the white area, snap it to the proper location on the underlying grid, and resize it by stretching the rectangle. According to the Properties sheet, JSC has assigned the id outputText1 to this component. Right click on the component and type Enter Name in the Value filed. Place another output text component under the first one, and set its value to Enter Password.

Drag the text field component for the user name and drop it by the first output text. Look at the Properties sheet - its id is textField1. Place a secret field component under the text filed - its id is secretField1.

Now drop the button on the screen - it already has a default value Submit.

Let's add some color to the page - click anywhere in the white area and pick up a nice background color from the Properties sheet. Change the title of the page to be My Logon Page.

After all these manipulations my screen looks as follows:

 

If you want to see what the generated code looks like, just click on the tab Source at the bottom of the page. This is what I've got:


<?xml version="1.0"?>
<jsp:root version="1.2" xmlns:f="http://java.sun.com/jsf/core"
 xmlns:h="http://java.sun.com/jsf/html" xmlns:jsp="http://java.sun.com/JSP/Page">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
  <f:view>
    <html>
      <head>
       <title>Page1 Title</title>
      </head>
      <body bgcolor="#00ffff" rave-layout="grid">
        <h:form binding="#{Page1.form1}" id="form1">
         <h:outputText binding="#{Page1.outputText1}" id="outputText1" 
           style="position: absolute; left: 24px; top: 24px; width: 
                             120px; height: 26px" value="Enter Name"/>
         <h:outputText binding="#{Page1.outputText2}" id="outputText2" 
           style="position: absolute; left: 24px; top: 72px; width: 
                         120px; height: 26px" value="Enter Password"/>
         <h:inputText binding="#{Page1.textField1}" id="textField1" 
           style="position: absolute; left: 168px; top: 24px; width: 
                                               120px; height: 23px"/>
         <h:commandButton action="#{Page1.button1_action}" 
            binding="#{Page1.button1}" id="button1" style="position: 
                    absolute; left: 24px; top: 120px" value="Submit"/>
         <h:outputText binding="#{Page1.outputText3}" id="outputText3" 
            style="position: absolute; left: 168px; top: 120px; width: 
                                                120px; height: 26px"/>
         <h:inputSecret binding="#{Page1.secretField1}" 
            id="secretField1" style="position: absolute; left: 168px; 
                               top: 72px; width: 120px; height: 23px"/>
        </h:form>
       </body>
      </html>
    </f:view>
</jsp:root>

Now we can build and deploy the project using provided Sun Application Server. Just press the big green arrow on the top toolbar, Ant will build and deploy the project, and JSC will start the application server and display our logon page:

 

Let's drop one more output text field outputText3 by the Submit button - we'll use it to see that the server responds when we submit the data.

JavaServer Faces uses event-driven interaction between a JSP and the server-side classes. For example, when a user clicks on the button Submit, appropriate listener intercepts this event and executes the code that you provide.

Double-click on the button Submit, and JSC will open the corresponding method in the underlying Java class. In our case it's a method button1_action() in the class Page1. Just type in the following two lines shown in blue to get the entered value, append it to the word Validating, and send the whole phrase back to the browser as the value of the field outputText3.


public String button1_action() {
    // Add your event code here...
    String name = (String) this.textField1.getValue();
    outputText3.setValue("Validating "+ name);
    return null;
}

Save this code and re-deploy the application by clicking on the green arrow. Enter any name and press the button Submit. Now the browser sends a request to your server, JSF calls the method button1_action(), and you'll see the response:

 

The next goal is to to validate the entered name against a database table.

Working With a Database
Java Studio Creator includes a PointBase DBMS with a sample database Travel. You have to start the PointBase server by selecting system menus Start | Programs | Sun Microsystems | J2EE 1.4 SDK | Start PointBase. This server starts quickly and displays a message in a command window that it's listening to the port 9092. Minimize this command window and return to JSC.

In the Server Navigator sheet, under the Data Sources expand the database Travel, which has the following data in the table Person:

PersonID Name Jobtitle FrequentFlyer
1 McNealy, Scott CEO true
2 Schwartz, Jonathan VPO/CXO - SGMS true
3 Green, Rich VP true
4 Joy, William VP/CXO - SGMS false
5 Gosling, James VP true

Every time when the user hits the button Submit on the logon page, we'll try to find the entered name in the list of names retrieved from the database table Person. In our simple application the password is password for any user.

The next step is to link our page with the data - drag and drop the table Person onto Page1.jsp. At this point JSF creates two new components - PersonRowSet, which is a JDBC RowSet and a PersonModel (remember similar implementation of the MVC pattern in some Swing components?) . You can see these names in the Document Outline sheet. Check out the constructor of the class Page1 - JSC has generated the following code:


public Page1() {
   // Creator-managed initialization code
   try {
     personRowSet.setDataSourceName("java:comp/env/jdbc/Travel");
     personRowSet.setCommand("SELECT * FROM ROOT.PERSON");
     personModel.setWrappedData(personRowSet);
   }
   catch ( Exception e) {
     log("Page1 Initialization Failure", e);
     throw new FacesException(e);
   }
   // User provided initialization code
}

Add the following line to this try/catch block to populate the personRowSet:


personRowSet.execute(); 

Now we should add the code that compares the entered name with names retrieved from the table Person. Modify the method button1_action() in Page1.java to process the RowSet. If the names match and the user has entered the word password , we'll assume that it's a valid user:


    public String button1_action() {
        // Add your event code here...
        String name = (String) this.textField1.getValue();
        String pwd = (String) this.secretField1.getValue();
        outputText3.setValue("Validating "+ name);
        boolean isValidUser=false;
        
        try{
            personRowSet.beforeFirst();

            while(personRowSet.next()){
             String personName = personRowSet.getString("NAME");

             if (name.equals(personName) && "password".equals(pwd)){
                outputText3.setValue( name + " is a valid user");
                isValidUser = true;
                break;
             }
            }
            if (!isValidUser){
               outputText3.setValue( name + ": logon failed");
            }
        } catch ( Exception e) {
            log("Can not access personRowSet: ", e);
            throw new FacesException(e);
        }

        return null;
    }
Here's what I've got after entering an valid name and password:

 

To test this application against another DBMS right click on the Data Sources and select Add Data Source option to configure a data source for any other DBMS. It'll work as long as you have a JDBC 3.0 driver for this DBMS.

Page Navigation
To make our logon example more realistic, let's introduce another page -the main page of some application that has to be displayed for valid users.

JSC has a cool Page Navigation tool, where you can define navigation rules for your application. Right click on our Page1.jsp and select Page Navigation from the menu. You'll see the following screen:

 

Now, right click on the Page1.jsp icon, select New Page and enter its name as WelcomePage. Click on the Page1.jsp icon again, drag the line to the WelcomePage icon and change the name of the line to validUser:

 

Click on the Source tab to see the content of the file Navigation.xml that JSC has generated:


<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces
 Config 1.0//EN"
  "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
<faces-config>
    <navigation-rule>
        <from-view-id>/Page1.jsp</from-view-id>
        <navigation-case>
            <to-view-id>/WelcomePage.jsp</to-view-id>
            <from-outcome>validUser</from-outcome>
        </navigation-case>
    </navigation-rule>
</faces-config>

This is how JavaServer Faces maps the outcome of the current page to the JSP that has to be displayed next.

Double click on the WelcomePage icon and add an output text component there with the value Welcome to My Application.

Finally, let's modify a little the code of the method button1_action() to return the value "validUser" in case of successful logon. This is how my while loop looks now:


           public String button1_action() {
        String name = (String) this.textField1.getValue();
        String pwd = (String) this.secretField1.getValue();
        try{
            personRowSet.beforeFirst();

            while(personRowSet.next()){
             String personName = personRowSet.getString("NAME");

             if (name.equals(personName) && "password".equals(pwd)){
                outputText3.setValue( name + " is a valid user");
                return "validUser";
             }
            }

            outputText3.setValue( name + ": logon failed");

        } catch ( Exception e) {
            log("Can not access personRowSet: ", e);
            throw new FacesException(e);
        }

        return null;
    }
}

Run the application again, and if you'll enter the valid name now, you'll see the next page:

 

During development of this application I've kept notes of what I did not like (do not forget - this is an early access release):

  • The name Java Studio Creator does not make any sense to me, since the tool is actually creating Web applications .
  • JSC starts slowly on my 1Ghz/1GB RAM/Windows 2000 notebook.
  • Undo option does not always work
  • Sometimes components were not shown in the designer, while the generated code was in place. And this is a showstopper - how many times are you willing to re-create the page from scratch?
  • After renaming the package, my Java code has disappeared.
  • Copy/paste is not fully functional yet.
  • Some modifications in the GUI designer do not sync up with Java code in the beans.
But overall, this test drive was a pleasant experience for me. After trying Java Studio Creator I want to learn JavaServer Faces technology! As a matter of fact I've already written my first logon application using JSF just now.

I was testing JSC while riding on a bus to work. A guy who was sitting next to me and watching what I was doing said: "It's like Visual Basic!". Well, it's not there yet. The Early Access edition of JSC is more like a concept car - you can get in, turn it on and touch the shiny controls. But when Sun will put it on the road, I'm sure that many Java developers who are currently driving on the server-side roads will buy it. But Sun Microsystems should move fast, because IBM has already announced the release of the WebSphere Studio V5.1.2, which will also include drag and drop programming with JavaServer Faces.

More Stories By Yakov Fain

Yakov Fain is a Java Champion and a co-founder of the IT consultancy Farata Systems and the product company SuranceBay. He wrote a thousand blogs (http://yakovfain.com) and several books about software development. Yakov authored and co-authored such books as "Angular 2 Development with TypeScript", "Java 24-Hour Trainer", and "Enterprise Web Development". His Twitter tag is @yfain

Comments (7) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Alexandre Barão 06/18/04 08:43:24 AM EDT

I do not really enjoy the process of creation of Web applications with JavaServer Pages but this article
shows the easy way to create a Web application... Thanks!
Alverca, Fado - Alemão! :)

jim caprioli 06/18/04 02:59:09 AM EDT

Some thoughts I had while reading your entertaining article.

- Concept cars give you this "if I only had..." feeling.
- I was very disappointing with this stuff.
- NetBeans does the job for me.
- So the guy ''in the bus'' is the VB user hey?
- Sun is a hardware company: ver good in compilers and Java. - I always end up at the site of JCreator when looking for info about this product.
- Worst name ever: "I just can''t remember it!"

GrtZ
jim

Yakov Fain 06/15/04 11:15:59 AM EDT

The article reads: "Add the following line to this try/catch block to populate the personRowSet:
personRowSet.execute();"

This means that you should put this line inside the try/catch block.

Regards,
Yakov Fain

Carol Cassles 06/15/04 11:10:08 AM EDT

Yakov Fain:

I followed the steps in your article very carefully. I got to the point where one adds the code that compares the entered name with names retrieved from the table Person. When I try to compile the source code I get a compiler error.

The error looks like this:

Compiling 1 source file to H:\My Documents\Creator\Projects\LOGONAUTH2\build\WEB-INF\classes
untitled\Page1.java [123] unreported exception java.sql.SQLException; must be caught or declared to be thrown
personRowSet.execute();
^
Are all of us newbees asking you how to "catch or declare" this command or is it just me?

Carol Cassles
[email protected]

Yakov Fain 05/25/04 02:28:03 PM EDT

Well, my laptop is not that bad - it has has 1Gb of RAM and 1Ghz processor :)

Winston Rast 05/25/04 02:07:49 PM EDT

I''m curious how you managed to boot Win2k in 1MB. :)

John Rubier 05/21/04 03:56:44 PM EDT

It runs slow?
I''m surprised much of anything runs at all on your "1Mhz/1MB RAM/Windows 2000 notebook"!

;-)

@ThingsExpo Stories
NHK, Japan Broadcasting, will feature the upcoming @ThingsExpo Silicon Valley in a special 'Internet of Things' and smart technology documentary that will be filmed on the expo floor between November 3 to 5, 2015, in Santa Clara. NHK is the sole public TV network in Japan equivalent to the BBC in the UK and the largest in Asia with many award-winning science and technology programs. Japanese TV is producing a documentary about IoT and Smart technology and will be covering @ThingsExpo Silicon Val...
SYS-CON Events announced today that Juniper Networks (NYSE: JNPR), an industry leader in automated, scalable and secure networks, will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Juniper Networks challenges the status quo with products, solutions and services that transform the economics of networking. The company co-innovates with customers and partners to deliver automated, scalable and secure network...
Grape Up is a software company, specialized in cloud native application development and professional services related to Cloud Foundry PaaS. With five expert teams that operate in various sectors of the market across the USA and Europe, we work with a variety of customers from emerging startups to Fortune 1000 companies.
Financial Technology has become a topic of intense interest throughout the cloud developer and enterprise IT communities. Accordingly, attendees at the upcoming 20th Cloud Expo at the Javits Center in New York, June 6-8, 2017, will find fresh new content in a new track called FinTech.
SYS-CON Events announced today that Interoute, owner-operator of one of Europe's largest networks and a global cloud services platform, has been named “Bronze Sponsor” of SYS-CON's 20th Cloud Expo, which will take place on June 6-8, 2017 at the Javits Center in New York, New York. Interoute is the owner-operator of one of Europe's largest networks and a global cloud services platform which encompasses 12 data centers, 14 virtual data centers and 31 colocation centers, with connections to 195 add...
In his keynote at @ThingsExpo, Chris Matthieu, Director of IoT Engineering at Citrix and co-founder and CTO of Octoblu, focused on building an IoT platform and company. He provided a behind-the-scenes look at Octoblu’s platform, business, and pivots along the way (including the Citrix acquisition of Octoblu).
SYS-CON Events announced today that CollabNet, a global leader in enterprise software development, release automation and DevOps solutions, will be a Bronze Sponsor of SYS-CON's 20th International Cloud Expo®, taking place from June 6-8, 2017, at the Javits Center in New York City, NY. CollabNet offers a broad range of solutions with the mission of helping modern organizations deliver quality software at speed. The company’s latest innovation, the DevOps Lifecycle Manager (DLM), supports Value S...
NHK, Japan Broadcasting, will feature the upcoming @ThingsExpo Silicon Valley in a special 'Internet of Things' and smart technology documentary that will be filmed on the expo floor between November 3 to 5, 2015, in Santa Clara. NHK is the sole public TV network in Japan equivalent to the BBC in the UK and the largest in Asia with many award-winning science and technology programs. Japanese TV is producing a documentary about IoT and Smart technology and will be covering @ThingsExpo Silicon Val...
@GonzalezCarmen has been ranked the Number One Influencer and @ThingsExpo has been named the Number One Brand in the “M2M 2016: Top 100 Influencers and Brands” by Analytic. Onalytica analyzed tweets over the last 6 months mentioning the keywords M2M OR “Machine to Machine.” They then identified the top 100 most influential brands and individuals leading the discussion on Twitter.
The 20th International Cloud Expo has announced that its Call for Papers is open. Cloud Expo, to be held June 6-8, 2017, at the Javits Center in New York City, brings together Cloud Computing, Big Data, Internet of Things, DevOps, Containers, Microservices and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding business opportunity. Submit your speaking proposal ...
The age of Digital Disruption is evolving into the next era – Digital Cohesion, an age in which applications securely self-assemble and deliver predictive services that continuously adapt to user behavior. Information from devices, sensors and applications around us will drive services seamlessly across mobile and fixed devices/infrastructure. This evolution is happening now in software defined services and secure networking. Four key drivers – Performance, Economics, Interoperability and Trust ...
The Internet of Things is clearly many things: data collection and analytics, wearables, Smart Grids and Smart Cities, the Industrial Internet, and more. Cool platforms like Arduino, Raspberry Pi, Intel's Galileo and Edison, and a diverse world of sensors are making the IoT a great toy box for developers in all these areas. In this Power Panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists discussed what things are the most important, which will have the most profound e...
Multiple data types are pouring into IoT deployments. Data is coming in small packages as well as enormous files and data streams of many sizes. Widespread use of mobile devices adds to the total. In this power panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists will look at the tools and environments that are being put to use in IoT deployments, as well as the team skills a modern enterprise IT shop needs to keep things running, get a handle on all this data, and deli...
With billions of sensors deployed worldwide, the amount of machine-generated data will soon exceed what our networks can handle. But consumers and businesses will expect seamless experiences and real-time responsiveness. What does this mean for IoT devices and the infrastructure that supports them? More of the data will need to be handled at - or closer to - the devices themselves.
SYS-CON Events announced today that Grape Up will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct. 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Grape Up is a software company specializing in cloud native application development and professional services related to Cloud Foundry PaaS. With five expert teams that operate in various sectors of the market across the U.S. and Europe, Grape Up works with a variety of customers from emergi...
@ThingsExpo has been named the Most Influential ‘Smart Cities - IIoT' Account and @BigDataExpo has been named fourteenth by Right Relevance (RR), which provides curated information and intelligence on approximately 50,000 topics. In addition, Right Relevance provides an Insights offering that combines the above Topics and Influencers information with real time conversations to provide actionable intelligence with visualizations to enable decision making. The Insights service is applicable to eve...
DevOps is often described as a combination of technology and culture. Without both, DevOps isn't complete. However, applying the culture to outdated technology is a recipe for disaster; as response times grow and connections between teams are delayed by technology, the culture will die. A Nutanix Enterprise Cloud has many benefits that provide the needed base for a true DevOps paradigm.
Bert Loomis was a visionary. This general session will highlight how Bert Loomis and people like him inspire us to build great things with small inventions. In their general session at 19th Cloud Expo, Harold Hannon, Architect at IBM Bluemix, and Michael O'Neill, Strategic Business Development at Nvidia, discussed the accelerating pace of AI development and how IBM Cloud and NVIDIA are partnering to bring AI capabilities to "every day," on-demand. They also reviewed two "free infrastructure" pr...
New competitors, disruptive technologies, and growing expectations are pushing every business to both adopt and deliver new digital services. This ‘Digital Transformation’ demands rapid delivery and continuous iteration of new competitive services via multiple channels, which in turn demands new service delivery techniques – including DevOps. In this power panel at @DevOpsSummit 20th Cloud Expo, moderated by DevOps Conference Co-Chair Andi Mann, panelists will examine how DevOps helps to meet th...
Five years ago development was seen as a dead-end career, now it’s anything but – with an explosion in mobile and IoT initiatives increasing the demand for skilled engineers. But apart from having a ready supply of great coders, what constitutes true ‘DevOps Royalty’? It’ll be the ability to craft resilient architectures, supportability, security everywhere across the software lifecycle. In his keynote at @DevOpsSummit at 20th Cloud Expo, Jeffrey Scheaffer, GM and SVP, Continuous Delivery Busine...