Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

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.

Thursday, August 2, 2007

Eclipse RCP 2 (a noobs account)

I'm going through the book Eclipse Rich Client Platform by McAffer and Lemieus and have been beating my head against the wall for a bit. In chapter four, they have you create an application named Hyperbola using the Hello RCP template. That all went well as I happily navigated the tutorial.

Now, here comes the part where I'm a bonehead. The book shipped with JDK 1.4 and Eclipse 3.1. The current version I'm using is Java 1.6 and Eclipse 3.3. Like an idiot I decided to try to navigate the book using the more recent distros. After all, who wants to use old stuff.

I noted some differences in my last blog about how things have changed. Well, here's another to add to the list. In chapter four they showed you how your plugin could remember the size and location of its window the last time the plug-in ran. Well, I left that in and spent a while trying to figure out why the tutorial in chapter five wouldn't work.

So, now for what went wrong.

When you use the Hello RCP template to generate a plug-in, it creates several java files. One of these is named ApplicationWorkbenchAdvisor.java. In chapter 4 they had you make the following modifications to that file.

public void initialize(IWorkbenchConfigurer configurer) {
// TODO Auto-generated method stub
configurer.setSaveAndRestore(true);
//super.initialize(configurer);
}

Well, for some reason when you make this change, it never calls createInitialLayout in Perspective.java which is what adds the new view to your perspective. So far I've tried running the configurer.setSaveRestore to true before and after the super class constructor but nothing seems to work.

I did eventually find a work-a-round at CT Armstrong's Blog. You can either delete the workbench.xml file from your target env or go to Run->Open Run Dialog and check Clear under Main->Workspace Data. You'll want to turn this back off or else you'll never save the position and size of your plug-ins window. The final version of my initalize method looks like this.

public void initialize(IWorkbenchConfigurer configurer) {
super.initialize(configurer);
configurer.setSaveAndRestore(true);
}



Good Luck(you'll need it)
Drifter

Monday, July 30, 2007

Eclipse RCP

I recently decided to upgrade my skill set and add Eclipse RCP to my list of things I almost know how to do. I purchased a book on the subject and gave it a whirl.

The book exhorts you to have two environments; one for you development environment and one for your deployment environment. I already had the Eclipse JAVA development environment at 3.3 so I downloaded RCP and installed it into a new directory. After this, you must go into window-preference then expand Plug-in Development->Target Platform to set your target platform to the RCP install location. I found I had to reselect all the Plug-ins it found in the RCP install location.

Next you create your project and the plug-in. The book left out the important step of configuring the environment the first time you use the RCP installation target. This is ignored in most tutorials (or is new in 3.3) due to the fact that the writers already have their environment set properly at the time the tutorial was developed.

The first thing that bit me was that there are subtle changes in the 3.1 to 3.3 versions of RCP. When you create your first plug-in, you'll find that IApplication no longer has a run() method. These have now been switched to start() and stop(). This, of course, blows the code compare function given by the book since the code base for 3.3 is different from 3.1. I grit my teeth and plow ahead.

Your first tutorial doesn't do much but pop up a screen. When you generate the plugin you get the following java files: Application, ApplicationActionBarAdvisor, ApplicationWorkbenchAdvisor, ApplicationWorkbenchWindowAdvisor, and Perspective.

Application.java is called at startup. Think of it as your entry point into the plug-in.

Perspective.java is where you create any views or editors you want the users to see when the plug-in is first invoked.

ApplicationWorkbenchAdvisor.java handles the GUI event loop. It has the following methods that can be overridden.
  • initialize() - called first to do such things as parse the command link, register adapters, and declare images
  • preStartup() - called after initialize but before the first window is opened.
ApplicationWorkbenchWindowAdvisor handles the windows customization like titles, placement and size.

ApplicationActionBarAdvisor creates and customizes information in the menu bar, cool bar (called tool bar most places) and the status line.

I've finished my first tutorial now and and off to the second. I'll post my problems and solutions here as I run into them

It had issues as well but I was able, in the end, to get it working in 3.3. This is the first tutorial. It has links to two others.

Good Luck (you'll need it)

Monday, May 14, 2007

Ubuntu Upgrade

I upgraded to Feisty Fawn version of Unbuntu. So far I found this problem with Rhythm Box.

http://johnny.chadda.se/2007/02/21/unlock-the-gnome-keyring-upon-login/

I finally gave up on it although I did learn a lot about passwords along the way. I eventually created a new key ring profile, then deleted the default one and renamed my new one to default. It didn't solve my problem but I did get past the one problem of not being able to edit it.

Other than that, everything in Ubuntu seven works well.

Here's an update: In a previous post I explained how to download and install Java 6. You don't need to undertake that long drawn out process any longer. It installs like any other package now. You still need to set the alternatives but the directory names are a bit different than my last post on the subject.

After you do the install via the normal package manager, do the following

  • sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java-6-sun/bin/java" 1
  • sudo update-alternatives --set java /usr/lib/jvm/java-6-sun/bin/java
  • java -version
You can always go back to a previous version but first you're going to need to find out what javas you have installed.

sudo update-alternatives --list java


This should allow you to use the 'set' command to set java to a previous version.

Sunday, January 21, 2007

Linux, Commies, and Capitolism

Note: How To's are located at bottom of post

Ok, for those of you who don't know what Linux is, crank up google and do a search. Its ok, I'll wait.

Ok, so now you know that Linux is a free operating system with a number of distributions from companies like Red Hat, SuSe, and others. Recently, at the advise of my java programing guru, I decided to try the Ubuntu version of Linux.

At first I typed in the wrong URL and went to Ubuntu.org which is a left leaning world community web site. I have nothing against left leaning community sites but I thought it was an odd place to store a Linux distribution. But then again, some raging capitalist believe the Linux development effort is lead by leftist radicals out to destroy the capitalist system as a whole. After all the thing is free!

What those folks don't understand is that the open source movement is built on the economics of ego, not dollars. You can download the source to the Linux kernel, make changes to it, compile it, and walla! You have your own operating system. For those of us with a semblance of life and a brain somewhat smaller than Jupiter this is a daunting task that we would never, ever, in a gagillion years undertake.

But luckily for us there are folks with brains the size of Jupiter that can do that and do it as a labor of love, pride the the ability to look down their nose at the rest of us that have, at least once in our lives, kissed a member of the opposite sex. But I digress.

I'm a wood-be java developer who is being guided on his virginal steps into Javadom but an experiance hack who works on an open source project that displays graphics for some of the games I enjoy. If you're interested you can go to the RPTools project web site.

I needed to reformat my aging laptop and decided to install Linux on it. I use Linux often and its my operating system of choice for home because I have teenagers who regularly virus anything with a Microsoft logo. Linux solved my woes and kept me from reinstalling Windows every other month.

So I took my old Dell Inspiron 8100 and and installed Ubuntu Linux. I liked the install process because it tool only one CD vs. the 4 that are required for Red Hat's Fedora Core or Suse Linux. The install went smoothly and I was up and running in no time. I installed Eclipse for Java development and upgraded the Java 1.4 to Java 5. Later I upgraded to Java 6.

Here's a list of things I did to get Ubuntu running on the laptop.


To install Java 5:
Open a terminal window.
sudo apt-get install sun-java5-jdk

And that's all there was to it.

Here's a link that discusses installing Tomcat as well.
http://www.spaceprogram.com/knowledge/2006/05/installing-java-5-jdk-and-tomcat-on.html

The next problem I ran into was Netscape Firefox had an issue. When I used the touch pad Firefox would navigate back to previous pages. This problem with Firefix and Unbuntu Linux was solved at the following link.

http://www.beginningubuntu.com/dapper_tips.html

Here's a quote from that page.

To configure the horizontal scroll of the touchpad to actually horizontally scroll a webpage, open Firefox, type about:config in the address box, and use that page's "Filter" text box to search for mousewheel.horizscroll.withnokey.action. Double-click the line in the results and set the value to 1, rather than 2. The change will be instant and permanent.
Later I decided to upgrade to Java 6 on Unbuntu Linux. Here are the steps I followed for that.

download java from http://java.sun.com/javase/downloads/index.jsp
cd to dowload directory
chmod a+x jdk-6-linux-i586.bin
sudo ./jdk-6-linux-i586.bin
sudo mv jdk1.6.0 /usr/lib/jvm/
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.6.0/bin/java" 1
sudo update-alternatives --set java /usr/lib/jvm/jdk1.6.0/bin/java
java -version

For those of you who want to just install the Java runtime, go to my fellow blogger's page for those instructions.

http://rchandran.blogspot.com/2006/12/as-java-se-1.html

The only downside to the install is that my Dell 725 printer wouldn't work on Linux. I contacted Dell support and was told that printer wouldn't work with Linux. This runs contrary to what I know about print drivers but who knows what Microsoft has done to squash other peoples attempt break away from the Microsoft and enter a world with people are paid with praise and knowledge of a job well done.