Welcome!

Java IoT Authors: Stackify Blog, Pat Romanski, Liz McMillan, Elizabeth White, Yeshim Deniz

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
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.
When growing capacity and power in the data center, the architectural trade-offs between server scale-up vs. scale-out continue to be debated. Both approaches are valid: scale-out adds multiple, smaller servers running in a distributed computing model, while scale-up adds fewer, more powerful servers that are capable of running larger workloads. It’s worth noting that there are additional, unique advantages that scale-up architectures offer. One big advantage is large memory and compute capacity...
In his session at @ThingsExpo, Eric Lachapelle, CEO of the Professional Evaluation and Certification Board (PECB), provided an overview of various initiatives to certify the security of connected devices and future trends in ensuring public trust of IoT. Eric Lachapelle is the Chief Executive Officer of the Professional Evaluation and Certification Board (PECB), an international certification body. His role is to help companies and individuals to achieve professional, accredited and worldwide re...
With major technology companies and startups seriously embracing Cloud strategies, now is the perfect time to attend 21st Cloud Expo October 31 - November 2, 2017, at the Santa Clara Convention Center, CA, and June 12-14, 2018, at the Javits Center in New York City, NY, and learn what is going on, contribute to the discussions, and ensure that your enterprise is on the right path to Digital Transformation.
No hype cycles or predictions of zillions of things here. IoT is big. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, Associate Partner at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He discussed the evaluation of communication standards and IoT messaging protocols, data analytics considerations, edge-to-cloud tec...
Amazon started as an online bookseller 20 years ago. Since then, it has evolved into a technology juggernaut that has disrupted multiple markets and industries and touches many aspects of our lives. It is a relentless technology and business model innovator driving disruption throughout numerous ecosystems. Amazon’s AWS revenues alone are approaching $16B a year making it one of the largest IT companies in the world. With dominant offerings in Cloud, IoT, eCommerce, Big Data, AI, Digital Assista...
SYS-CON Events announced today that CA Technologies has been named "Platinum Sponsor" of SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. CA Technologies helps customers succeed in a future where every business - from apparel to energy - is being rewritten by software. From planning to development to management to security, CA creates software that fuels transformation for companies in the applic...
Artificial intelligence, machine learning, neural networks. We’re in the midst of a wave of excitement around AI such as hasn’t been seen for a few decades. But those previous periods of inflated expectations led to troughs of disappointment. Will this time be different? Most likely. Applications of AI such as predictive analytics are already decreasing costs and improving reliability of industrial machinery. Furthermore, the funding and research going into AI now comes from a wide range of com...
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 looked 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 deliver...
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devic...
SYS-CON Events announced today that Cloud Academy named "Bronze Sponsor" of 21st International Cloud Expo which will take place October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara, CA. Cloud Academy is the industry’s most innovative, vendor-neutral cloud technology training platform. Cloud Academy provides continuous learning solutions for individuals and enterprise teams for Amazon Web Services, Microsoft Azure, Google Cloud Platform, and the most popular cloud com...
SYS-CON Events announced today that Enzu will exhibit at SYS-CON's 21st Int\ernational Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Enzu’s mission is to be the leading provider of enterprise cloud solutions worldwide. Enzu enables online businesses to use its IT infrastructure to their competitive advantage. By offering a suite of proven hosting and management services, Enzu wants companies to focus on the core of their ...
We build IoT infrastructure products - when you have to integrate different devices, different systems and cloud you have to build an application to do that but we eliminate the need to build an application. Our products can integrate any device, any system, any cloud regardless of protocol," explained Peter Jung, Chief Product Officer at Pulzze Systems, in this SYS-CON.tv interview at @ThingsExpo, held November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA
SYS-CON Events announced today that GrapeUp, the leading provider of rapid product development at the speed of business, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. 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 acr...
SYS-CON Events announced today that Ayehu will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara California. Ayehu provides IT Process Automation & Orchestration solutions for IT and Security professionals to identify and resolve critical incidents and enable rapid containment, eradication, and recovery from cyber security breaches. Ayehu provides customers greater control over IT infras...
SYS-CON Events announced today that MobiDev, a client-oriented software development company, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. MobiDev is a software company that develops and delivers turn-key mobile apps, websites, web services, and complex software systems for startups and enterprises. Since 2009 it has grown from a small group of passionate engineers and business...
In his session at Cloud Expo, Alan Winters, an entertainment executive/TV producer turned serial entrepreneur, presented a success story of an entrepreneur who has both suffered through and benefited from offshore development across multiple businesses: The smart choice, or how to select the right offshore development partner Warning signs, or how to minimize chances of making the wrong choice Collaboration, or how to establish the most effective work processes Budget control, or how to ma...
"When we talk about cloud without compromise what we're talking about is that when people think about 'I need the flexibility of the cloud' - it's the ability to create applications and run them in a cloud environment that's far more flexible,” explained Matthew Finnie, CTO of Interoute, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
IoT solutions exploit operational data generated by Internet-connected smart “things” for the purpose of gaining operational insight and producing “better outcomes” (for example, create new business models, eliminate unscheduled maintenance, etc.). The explosive proliferation of IoT solutions will result in an exponential growth in the volume of IoT data, precipitating significant Information Governance issues: who owns the IoT data, what are the rights/duties of IoT solutions adopters towards t...
With the introduction of IoT and Smart Living in every aspect of our lives, one question has become relevant: What are the security implications? To answer this, first we have to look and explore the security models of the technologies that IoT is founded upon. In his session at @ThingsExpo, Nevi Kaja, a Research Engineer at Ford Motor Company, discussed some of the security challenges of the IoT infrastructure and related how these aspects impact Smart Living. The material was delivered interac...