Welcome!

Java IoT Authors: Pat Romanski, Liz McMillan, Elizabeth White, Stackify Blog, 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
The 21st International Cloud Expo has announced that its Call for Papers is open. Cloud Expo, to be held October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, brings together Cloud Computing, Big Data, Internet of Things, DevOps, Digital Transformation, Machine Learning 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 busin...
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with the 21st International Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. @ThingsExpo Silicon Valley Call for Papers is now open.
As cloud adoption continues to transform business, today's global enterprises are challenged with managing a growing amount of information living outside of the data center. The rapid adoption of IoT and increasingly mobile workforce are exacerbating the problem. Ensuring secure data sharing and efficient backup poses capacity and bandwidth considerations as well as policy and regulatory compliance issues.
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.
SYS-CON Events announced today that SoftLayer, an IBM Company, has been named “Gold Sponsor” of SYS-CON's 18th Cloud Expo, which will take place on June 7-9, 2016, at the Javits Center in New York, New York. SoftLayer, an IBM Company, provides cloud infrastructure as a service from a growing number of data centers and network points of presence around the world. SoftLayer’s customers range from Web startups to global enterprises.
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...
SYS-CON Events announced today that Outscale 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. Outscale's technology makes an automated and adaptable Cloud available to businesses, supporting them in the most complex IT projects while controlling their operational aspects. You boost your IT infrastructure's reactivity, with request responses that only take a few seconds.
SYS-CON Events announced today that Loom Systems 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. Founded in 2015, Loom Systems delivers an advanced AI solution to predict and prevent problems in the digital business. Loom stands alone in the industry as an AI analysis platform requiring no prior math knowledge from operators, leveraging the existing staff to succeed in the digital era. With offices in S...
SYS-CON Events announced today that DivvyCloud 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. DivvyCloud software enables organizations to achieve their cloud computing goals by simplifying and automating security, compliance and cost optimization of public and private cloud infrastructure. Using DivvyCloud, customers can leverage programmatic Bots to identify and remediate common cloud problems in rea...
SYS-CON Events announced today that Tintri, Inc, a leading provider of enterprise cloud infrastructure, 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. Tintri offers an enterprise cloud platform built with public cloud-like web services and RESTful APIs. Organizations use Tintri all-flash storage with scale-out and automation as a foundation for their own clouds – to build agile development environments...
SYS-CON Events announced today that Progress, a global leader in application development, has been named “Bronze Sponsor” of 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. Enterprises today are rapidly adopting the cloud, while continuing to retain business-critical/sensitive data inside the firewall. This is creating two separate data silos – one inside the firewall and the other outside the firewall. Cloud ISVs ofte...
SYS-CON Events announced today that Tappest will exhibit MooseFS 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. MooseFS is a breakthrough concept in the storage industry. It allows you to secure stored data with either duplication or erasure coding using any server. The newest – 4.0 version of the software enables users to maintain the redundancy level with even 50% less hard drive space required. The software func...
SYS-CON Events announced today that Interoute has been named “Bronze Sponsor” of 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. Interoute is the owner operator of Europe's largest network and a global cloud services platform, which encompasses over 70,000 km of lit fiber, 15 data centers, 17 virtual data centers and 33 colocation centers, with connections to 195 additional partner data centers. Our full-service Unifie...
SYS-CON Events announced today that EARP 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. "We are a software house, so we perfectly understand challenges that other software houses face in their projects. We can augment a team, that will work with the same standards and processes as our partners' internal teams. Our teams will deliver the same quality within the required time and budget just as our partn...
SYS-CON Events announced today that Carbonite 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. Carbonite protects your entire IT footprint with the right level of protection for each workload, ensuring lower costs and dependable solutions with DoubleTake and Evault.
SYS-CON Events announced today that Super Micro Computer, Inc., a global leader in compute, storage and networking technologies, 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. Supermicro (NASDAQ: SMCI), the leading innovator in high-performance, high-efficiency server technology, is a premier provider of advanced server Building Block Solutions® for Data Center, Cloud Computing, Enterprise IT, Hadoop/...
SYS-CON Events announced today that Technologic Systems Inc., an embedded systems solutions company, will exhibit at SYS-CON's @ThingsExpo, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Technologic Systems is an embedded systems company with headquarters in Fountain Hills, Arizona. They have been in business for 32 years, helping more than 8,000 OEM customers and building over a hundred COTS products that have never been discontinued. Technologic Systems’ pr...
SYS-CON Events announced today that Progress, a global leader in application development, has been named “Bronze Sponsor” of 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. Enterprises today are rapidly adopting the cloud, while continuing to retain business-critical/sensitive data inside the firewall. This is creating two separate data silos – one inside the firewall and the other outside the firewall. Cloud ISVs oft...
SYS-CON Events announced today that Cloudistics, an on-premises cloud computing company, has been named “Bronze Sponsor” of 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. Cloudistics delivers a complete public cloud experience with composable on-premises infrastructures to medium and large enterprises. Its software-defined technology natively converges network, storage, compute, virtualization, and management into a ...
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...