Tigerfarm Tigerfarm

Computers, Localization, Travel, Southeast Asia, Sun Microsystems, Writing
Main | Next page »

Open Source Course Content: Web 2.0 | Frameworks | Solaris
Wednesday Aug 26, 2009

JSF 2.0, NetBeans 6.8, and GlassFish

Following are steps to get JSF 2.0 running on GlassFish, and can develop JSF 2.0 projects in NetBeans. Also, included are NetBeans project using JSF 2.0, and JSF 2.0 with some new Facelets functions.
Below is a screen shot of the JSF 2.0 selection step in NetBeans 6.8.

NetBeans 6.8 is packaged with GlassFish v3, which, I believe (I did not test), includes JSF 2.0.
Because I am running GlassFish V2, I followed the instructions to download the JSF JAR files to update my GlassFish for JSF 2.0:
Installing Mojarra 2.0.0 RC on GlassFish v2
* download the Mojarra 2.0.0 RC binary bundle bundle from the project page.
- filename: mojarra-2.0.0-RC-binary.zip
* backup your existing jsf-impl.jar found in GF_HOME/lib
* copy the new jsf-api and jsf-impl JARs to GF_HOME/lib
* edit your GF_HOME/domains/<domain-name>/config/domain.xml and
- add (or update the existing classpath-prefix) 'classpath-prefix="${com.sun.aas.installRoot}/lib/jsf-api.jar" to the java-config element
- Example: <java-config classpath-suffix="" classpath-prefix="${com.sun.aas.installRoot}/lib/jsf-api.jar" ... >
* Restart the GlassFish server
Note, the above instructions from: https://javaserverfaces.dev.java.net/nonav/rlnotes/2.0.0/releasenotes.html

Install NetBeans 6.8:
* To download NetBeans 6.8, click on 6.8 M1, from the NetBeans download page: http://www.netbeans.org/downloads/index.html
- Filename: netbeans-6.8_m1-java-windows.exe
* Run the installation.

Now that you have a JSF 2.0 GlassFish version, and NetBeans 6.8, you are ready to develop JSF 2.0 projects.
* Start NetBeans.
* Select New Project/Java Web/Web Application. In the project form, enter:
- Project Name: jsf1
- Project Location: C:\java\jsf\samples
- Click Next.
- The Server selected is your JSF 2.0 GlassFish version.
- Click Next.
- Check JavaServer Faces, which then displays JSF 2.0 configuration information.
- Click Finish.
*** You now have your first JSF 2.0 NetBeans Project ready to run.

Descriptions of the jsf1 project files, under the Projects tab: jsf1/Web Pages:
- forwardToJSF.jsp : the project's home page which uses the JSF Servlet URL Pattern (faces/) to forward the browser to the first JSF page:
<jsp:forward page="faces/template-client.xhtml"/>
- template-client.xhtml : JSF 2.0 page, which uses a Facelets template.
- template.xhtml : Facelets template
- In the directory jsf1/Web Pages/WEB-INF, are the configuration files: web.xml and faces-config.xml
* Run the project.

There are sample JSF 2.0 code which can be downloaded in the Mojarra 2.0.0 RC binary bundle. I have built one and zipped it up for your convience:
Click here to download jsf2ajax.zip, a JSF 2.0 code sample NetBeans Project.

Enjoy JSF 2.0, Stacy Thurston, Sun Learning Services developer.

Friday Aug 21, 2009

MySQL 5.1 with NetBeans 6.7

By example, this is how I installed and configured MySQL, then modified a NetBeans Java EE project to switch from using JavaDB to MySQL. Can be done in under an hour.

Download, Install, and Configure MySQL

Download MySQL 5.1: http://dev.mysql.com/downloads/mysql/5.1.html
File downloaded: mysql-5.1.37-win32.msi, about 100 meg
Install:
* double click on mysql-5.1.37-win32.msi
* Welcome page is displayed. Click Next.

* Use default, Custom, click Next.
- Default installation directory (Destination Folder): C:\Program Files\MySQL\MySQL Server 5.1\
- Open MySQL Server branch, click on MySQL Server Datafiles, click Change button.
- Set destination folder (Data Folder) to C:\sun\mysql, click OK.
- Remove documentation from install
- To be installed: MySQL Server, Client Programs, MySQL Instance Manager.
- No other changes.
- Click Next.
* Echoes the above selections. Click Install.
* Software installs. MySQL notices come up. Click Next on each.
* Wizard Completed is displayed. Configure the MysSQL Server now, is checked.
Click Finish.
* Welcome to the MySQL Server Instance Configuration Wizard is displayed. Click Next.
* Choose Standard Configuration. Click Next.
* Install As Windows Service is checked,
- Service Name: MySQL,
- Launch automatically is unchecked,
- Include Bin Directory in Windows PATH is checked.
- Click Next.
* Enter a root password, example root. Click Next.
* Ready to execute, is displayed. Click Execute.
*** The first time, it failed to start the server. I restarted my computer.
On restart, I click: Start/All Programs/MySQL/MySQL Server 5.1/MySQL Server Instance Configuration.
Note, I can run this at anytime.

The installation and configuration is completed. And an database instance has been created.

use the Windows Services Manager to start and stop the MySQL instance.


Create a Database

Sample simple commands: http://dev.mysql.com/doc/world-setup/en/world-setup.html

My steps:

>mysql -u root -p
mysql> create database studentdb;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| studentdb          |
| test               |
+--------------------+
4 rows in set (0.00 sec)

Now I have MySQL Server instance running, and a database created.


Modify the NetBeans Project to use MySQL

In NetBeans:
Under Services tab, Databases/Drivers, right mouse click MySQL (Connector/J driver) select Connect using.
In the popup, enter:

Name: MySQL (Connector/J driver)
Host: localhost
Port: 3306
Database: studentdb
User Name: root
Password: root
Remember password is checked.
Click OK

A connection is now under the Services tab, Databases. jdbc:mysql://localhost:3306/studentdb [root]

In the NetBeans Java EE EJB project:
Make a backup of the JavaDB persistence.xml file, which is under the project's setup folder: copy to persistenceJavaDB.xml.
In persistence.xml, I select Data Source: New Data Source ...
In the popup:

   JNDI Name: mysql/studentdb
   Database Connection: jdbc:mysql://localhost:3306/studentdb [root]
   Click OK


Clean and build EJB project.
Clean and build Java EE project.
Deploy and test.
*** Works with the MySQL database.


View New Rows in the Database

Use either MySQL command line utility, or Connect and Execute command in NetBeans.

>mysql -u root -p

mysql> use studentdb;
Database changed
mysql> show tables;
Empty set (0.00 sec)

mysql> show tables;
+---------------------+
| Tables_in_studentdb |
+---------------------+
| address             |
| dorm                |
| sequence            |
| student             |
| studentmajor        |
+---------------------+
5 rows in set (0.00 sec)

mysql> select * from studentmajor;
+----+---------+
| ID | NAME    |
+----+---------+
|  1 | English |
|  2 | Science |
+----+---------+
2 rows in set (0.00 sec)

Done, tested, and verified!.


GlassFish Resource Configuration

In the above, the persistence resource is configured using NetBeans wizards.
Following are screen prints of the configurations created in GlassFish by NetBeans. This can be used to setup a resource in GlassFish, without using NetBeans.


GlassFish Resource Configuration on Solaris

Monday Aug 04, 2008

JavaFX SDK for NetBeans Samples

Screen prints from each of the JavaFX SDK for NetBeans Samples are printed below.
Download: http://java.sun.com/javafx/downloads/

Screen prints and descriptions of the Java FX Sample Programs were done by: Riley Thurston, August 1, 2008


Arctangent-Circles follow cursor
Math-Arctangent

Background Image-Has Moving red line
Image-Background

Bounce-Game
Game-Bounce

Bouncy Bubbles-Bubbles fall to floor bouncing with eachother
Motion-BouncyBubbles

Clock-Tell time with clock
Input-Clock

Color Wheel-Displays colors
Color-ColorWheel

Constratin-Move cursor with circle
Input-Constrain

Displaying-Shows Image
Image-Displaying

Distance 1D-Move cursor with lines
Math-Distance1D

Distance 2D-Move cursor with circles
Math-Distance2D

Easing-Move cursor and circle will follow
Input-Easing

Flocks-Tiny triangles move across the background
Simulation-Flocks

Linear-Moving white line
Motion-Linear

Linear Gradient-Displays Image
Color-GradientSample

Milliseconds-Flashes to seconds
Input-Milliseconds

Mouse 1D-Squares grow larger and smaller to the cursor
Input-Mouse1D

Mouse 2D-Move the squares with the cursor
Input-Mouse2D

Mouse Press-A digital mouse, if you click your own mouse, it will show on screen
Input-MousePress

Points and Lines-Displays an image
Forms-Points&Lines

Rotate-Moving square
Transform-Rotate

Scale-Square grows and shrinks
Transform-Scale

Shape Primitives-Displays an image
Forms-ShapePrimitives

Simple Particle System-Lots of falling circles
Simulation-SimpleParticleSystem

Sine-Shape expands and contracts
Math-Sine

SineWave-Wave of circles
Math-SineWave

Smoke Particle System-Control the flow of smoke with cursor
Simulation-SmokeParticleSystem

Storing Input-Create circles with cursor that fade away
Input-Storing

Translate-Two moving squares
Transform-Translate

Transparency-Java FX sign will follow cursor
Image-Transparency

Wednesday Jun 11, 2008

Teenagers Getting Started with Java

My son turned 16 a few days ago, he has done some Java programing, and JavaScript programming. JavaScript is the computer language used to make web sites highly interactive; Facebook and Google Maps use it.

For Java programming,
An excellent beginner book: Java in Easy Steps by Mike McGrath.
* I had my son do a number of programs from this book to learn the basics of programming: variable types, if and while loops, etc. To write Java programs, my son started by using Bluejay (http://www.bluej.org/). There is a book with a description on the web site; I have not seen the book. When I looked at the description, I would stay with Java in Easy Steps.
Since I can sit with my son and help him because I am a Java programmer, I have taught him to use NetBeans(http://www.NetBeans.org). He is fine with it.NetBeans also works for JavaScript.

Recommendation,

  • Use the Java in Easy Steps book to get started. After learning the basics, can move to the Bluejay book.
  • If you have an experience developer use NetBeans, else use Bluejay.
  • Once started with the basics of Java, have a look at the Greenfoot site, http://www.greenfoot.org/. This was recommended to me by James Gosling. It is a bit of game or scenario type learning environment for Java.
That should be plenty to get you started.

Wednesday Jan 02, 2008

Training Trainers in Shanghai

Shanghai, Dec.22, 3 days before Christmas, I'm training some Sun Microsystems Java trainers, and Partner trainers from Beijing and Shanghai. The class of 5 people is half good at English so I use lots of diagrams and write point form on a white board to help clarify my points. My hope is they can now work through the labs and be able to teach the one day seminar about Java EE web site Frameworks.

One of the students, 周羽 (2 from the right in class photo below), modified my struts examples to use spring. I am now analyzing his NetBeans projects for use in future teachings. His notes are below, I have added his samples to the Framework download zip file.

During lunch, a few of us went for Japanese food which was good. After the class, Lily (right most in class photo below) and I went for excellent wong tong at a tourist area. It was fun eating, shopping, and walking around. The difficult part was finding taxis because it was lightly raining and we were in busy areas which meant competition for taxis.

Click here to view all my China Trip photos.

Class photo


The First Way.
The addGameAction must be extended ActionSupport(ActionSupport is a class from Spring). And use ApplicationContext.getBean() to get LeagueService. I don't like this way because it's too close-coupled.

The Second Way.
The addGameAction still extend Action(Class of Struts).But add 1 attribute in addGameAction.The attribute is LeagueService. Change the default RequestProcessor to org.springframework.web.struts.DelegatingRequestProcessor. Then can Dependency Injection via Spring. This way is better than first way.But it isn't the best way because it's changed default RequestProcessor in Struts.

The Third Way.
Still Inject the LeagueService via Spring.But it's no need to change the default RequestProcessor. It's AOP.Use the Spring interceptor to intercept Action class. In struts-config.xml,change the "Writen by 周羽.

Wednesday Nov 28, 2007

China Sun Learning Event Dec.17-20

In Beijing, Dec.17-18, and Shanghai, Dec.19-20, Sun Microsystems is hosting a Learning Technology Event covering the following:
Java Topics: Java Architect and Design, Web 2.0, Spring Framework, GlassFish, Certification preparations
Solaris Topics: Security, ZFS, DTrace, Containers, Certification preparations
Operation Technology: Risk management, Disaster Recovery, DRP, Business Continuity
Other: Partner and employee seminars, and in Beijing, there is an exam centre

I will be teaching:
* Web 2.0 which is Ajax, CSS, JavaScript, and demo the DojoToolkit and jMaki.
*** Click here to preview course materials and demo programs.
* Developing MVC web applications using the Spring Framework.
*** Click here to preview course materials and demo programs: Modules 1,2,3,7

For details of the daily events, click on the images below.