Welcome!

Java IoT Authors: Yeshim Deniz, Pat Romanski, Liz McMillan, Elizabeth White, Frank Lupo

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
High-velocity engineering teams are applying not only continuous delivery processes, but also lessons in experimentation from established leaders like Amazon, Netflix, and Facebook. These companies have made experimentation a foundation for their release processes, allowing them to try out major feature releases and redesigns within smaller groups before making them broadly available. In his session at 21st Cloud Expo, Brian Lucas, Senior Staff Engineer at Optimizely, will discuss how by using...
In this strange new world where more and more power is drawn from business technology, companies are effectively straddling two paths on the road to innovation and transformation into digital enterprises. The first path is the heritage trail – with “legacy” technology forming the background. Here, extant technologies are transformed by core IT teams to provide more API-driven approaches. Legacy systems can restrict companies that are transitioning into digital enterprises. To truly become a lead...
SYS-CON Events announced today that CAST Software 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. CAST was founded more than 25 years ago to make the invisible visible. Built around the idea that even the best analytics on the market still leave blind spots for technical teams looking to deliver better software and prevent outages, CAST provides the software intelligence that matter ...
SYS-CON Events announced today that Daiya Industry will exhibit at the Japanese Pavilion 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. Ruby Development Inc. builds new services in short period of time and provides a continuous support of those services based on Ruby on Rails. For more information, please visit https://github.com/RubyDevInc.
As businesses evolve, they need technology that is simple to help them succeed today and flexible enough to help them build for tomorrow. Chrome is fit for the workplace of the future — providing a secure, consistent user experience across a range of devices that can be used anywhere. In her session at 21st Cloud Expo, Vidya Nagarajan, a Senior Product Manager at Google, will take a look at various options as to how ChromeOS can be leveraged to interact with people on the devices, and formats th...
SYS-CON Events announced today that Yuasa System will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. Yuasa System is introducing a multi-purpose endurance testing system for flexible displays, OLED devices, flexible substrates, flat cables, and films in smartphones, wearables, automobiles, and healthcare.
SYS-CON Events announced today that Taica will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. Taica manufacturers Alpha-GEL brand silicone components and materials, which maintain outstanding performance over a wide temperature range -40C to +200C. For more information, visit http://www.taica.co.jp/english/.
Enterprises have taken advantage of IoT to achieve important revenue and cost advantages. What is less apparent is how incumbent enterprises operating at scale have, following success with IoT, built analytic, operations management and software development capabilities – ranging from autonomous vehicles to manageable robotics installations. They have embraced these capabilities as if they were Silicon Valley startups. As a result, many firms employ new business models that place enormous impor...
SYS-CON Events announced today that SourceForge has been named “Media Sponsor” of 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. SourceForge is the largest, most trusted destination for Open Source Software development, collaboration, discovery and download on the web serving over 32 million viewers, 150 million downloads and over 460,000 active development projects each and every month.
SYS-CON Events announced today that Dasher Technologies 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. Dasher Technologies, Inc. ® is a premier IT solution provider that delivers expert technical resources along with trusted account executives to architect and deliver complete IT solutions and services to help our clients execute their goals, plans and objectives. Since 1999, we'v...
As popularity of the smart home is growing and continues to go mainstream, technological factors play a greater role. The IoT protocol houses the interoperability battery consumption, security, and configuration of a smart home device, and it can be difficult for companies to choose the right kind for their product. For both DIY and professionally installed smart homes, developers need to consider each of these elements for their product to be successful in the market and current smart homes.
SYS-CON Events announced today that MIRAI Inc. will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. MIRAI Inc. are IT consultants from the public sector whose mission is to solve social issues by technology and innovation and to create a meaningful future for people.
SYS-CON Events announced today that Massive Networks, that helps your business operate seamlessly with fast, reliable, and secure internet and network solutions, has been named "Exhibitor" of 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. As a premier telecommunications provider, Massive Networks is headquartered out of Louisville, Colorado. With years of experience under their belt, their team of...
SYS-CON Events announced today that TidalScale, a leading provider of systems and services, 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. TidalScale has been involved in shaping the computing landscape. They've designed, developed and deployed some of the most important and successful systems and services in the history of the computing industry - internet, Ethernet, operating s...
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, will discuss how from store operations...
In a recent survey, Sumo Logic surveyed 1,500 customers who employ cloud services such as Amazon Web Services (AWS), Microsoft Azure, and Google Cloud Platform (GCP). According to the survey, a quarter of the respondents have already deployed Docker containers and nearly as many (23 percent) are employing the AWS Lambda serverless computing framework. It’s clear: serverless is here to stay. The adoption does come with some needed changes, within both application development and operations. Tha...
SYS-CON Events announced today that IBM has been named “Diamond Sponsor” of SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California.
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, will lead you through the exciting evolution of the cloud. He'll look at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering ...
Infoblox delivers Actionable Network Intelligence to enterprise, government, and service provider customers around the world. They are the industry leader in DNS, DHCP, and IP address management, the category known as DDI. We empower thousands of organizations to control and secure their networks from the core-enabling them to increase efficiency and visibility, improve customer service, and meet compliance requirements.