Friday, May 28, 2010

Google And Linux

I am happy to report that Google now supports Linux for the Chrome browser. It was a painless install but I had to close Firefox in order for Chrome to import my settings.  Now I'm off to see if the Goggle Web Toolkit actually works with Linux now.

Sunday, May 9, 2010

JSF 1.2 – Eclipse 3.5.2 – JBOSS 5.1

My philosophy has always been "programming should be easy."  I confess that for me it always has been easy.  Picking up new languages isn't hard.  For me concepts flow and paradigms shift without much difficulty.  I use Eclipse as my IDE of choice due to the variety of languages I use.  With Eclipse I can quickly move back and forth between Perl, PHP, Groovy, Ruby, Java, C, SQL and HTML without ever leaving Eclipse.  I love it.

So enter my decision to take up Java Enterprise Web applications.  I've used Java for a number of years now so figured there wouldn't be that big a transition to JEE Web apps.  And while I still hope that is the case, my first attempt at getting a simple app up and running took far longer than it should have. 

First, a little background on the project: I've had this standard project I do in any new language or frame work which constructs a star sector 20 light years across.  Its a great object oriented exercise due to the implicit inheritances and mutation of the star systems, stars, planets, moons and asteroids. 

Since any good project starts with a good database design, I started on the database and Data Transfer Objects incorporating a DAO factory for the pattern.  All that went really well.

Once I had star systems generating properly, it was time to put up a web page to display the information.  It was then I hit molasses.

I settled on a JSF/Richfaces display layer utilizing JBOSS as the JEE container.  The boring details are JSF 1.2, JBOSS 5.1 and Eclipse 3.5.1. 

Rather than give you all the false starts, I'm going to detail what actually worked.  I'll leave the complaining for another blog. 

There really isn't any configuration required for Eclipse or JBOSS so after you've installed JBOSS and Eclipse, bring up Eclipse and switch to the JEE perspective.  Down at the bottom there will be a Servers tab.  Right click New and set up your JBOSS Server.

Next, go to File->New->Dynamic Web Project.  You'll need to give it a name like Eclipse35Jboss51JSF, select JBOSS 5.0 as the target runtime, Dynamic Web Module Version 2.5, and Configuration of JavaServer Faces 1.2.  (see screen below).  Click Finish to create the project.



Now comes the odd part for me.  I've just added the JSF libraries to my build
path but since JBOSS 5.1 has these included you now need to make sure they don't make it into your WAR.  Right click on the project name -> Properties -> Project Facets -> Java Server Faces and toggle the "Include libraries with this application" check box (see below)




Now go back to your project.  You'll be creating two files (index.html and index.jsp).

Right click on the WebContent folder->New->HTML.  For some reason the remains obscure, if you reference the faces file directly it doesn't work.  Its almost as though you need to give JBOSS a little time to compile the servlet. Mare your HTML file look something like this


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Refresh" content= "0; URL=index.faces"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Starting Web App</title>
</head>
<body>
<p>The application will be with you shortly. :-)</p>

</body>
</html>

Basically you just add the redirect, change the title, and put a wee bit of content in the page.


Now create your jsf file named index.jsp.  WebContent->New->JSP


After filling in the file name hit NEXT>
Eclispe does some nice things for (and sometimes to) you.  In this case you can let it fill in the JSF tags for you.  On the next screen you'll get a list of templates.  Select the first one. (see below)


Now you can add some JSF content to your page.

You can add this code snippet between the and 





<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>New Title</title>
</head>
<body>
<f:view>
<h:form id="searchForm">

<h:outputText id="ot1" value="Search Text: "/>
<h:inputText id="it1"/> <br />
<h:commandButton id="cb1" value="Go"/> <br />
<h:commandLink id="cl1" value="About Page"/>

</h:form>
</f:view>
</body>
</html>


Now save everything and deploy it to JBOSS by right clicking on the project name->Run As->Run On Server then selecting JBOSS 5.0 and finish.  If you did everything correctly you should get something like.



Good luck and let me know if it worked.

I'll be posting project updates as the weeks roll on.