Posts Tagged jsf

update: maven + seam numberguess demo

Well… I finally got around to cleaning this up and getting it completely converted over to maven2 using seam 2.0.0.BETA1.

The troubles I had with the ear plugin went away when I move to maven 2.0.9!

Here is the quick and dirty:

% wget http://brianin3d.googlepages.com/in3.tgz
% tar xfz in3.tgz 
% cd in3/
% mvn package
% cp ear/target/in3.ear .  
% mv in3.ear ${JBOSS_HOME}/server/default/deploy/in3.ear 

hit it as http://localhost:8080/seam-numberguess-mvn

Next up, I want to try a bigger app like the dvd-store example.

Then I should be able to create an archetype 😀

For now, the tarball makes a pretty good maven2 starting point for some types of fun

Comments (2)

how ’bout a nice game of mvn+seam+jsf mit jboss?

I spent some time looking for a good recent archetype to do this that actually worked before giving up and deciding to do it in 3 easy pieces as part of a multiproject.

Since I’m pretty gnu to seam/jsf, I decided to start with seam-numberguess-2.1.0.CR1.ear and put it back together again.

Sadly, this process didn’t result in a completely clean solution… in the end I couldn’t quite get the ear plugin to do what I wanted and ended up overriding the application.xml, jboss-app.xml, jamming some stuff into a lib dir in the ear etc.. Hope to clean it up at some point.

Perhaps you can get softeu to work for you… for me it just blowed up in various interesting ways…

multiproject

groupId=jsf-in3
package=us.versus.them.demos.jsf.in3
version=1.0.0-SNAPSHOT
common="-DgroupId=${groupId} -DpackageName=${package} -Dversion=${version}"
webapp=-DarchetypeArtifactId=maven-archetype-webapp

mvn archetype:create ${common} -DartifactId=in3-project
cd in3-project
cat pom.xml | sed 's,>jar<,>pom<,' > fu
mv fu pom.xml
mvn archetype:create ${common} -DartifactId=in3-jar
mvn archetype:create ${common} ${webapp} -DartifactId=in3-war
mvn archetype:create ${common} ${webapp} -DartifactId=in3-ear

Unfortunately, there is a lot more junk that has to be done by hand… Stuff that is really pretty dumb.

java 5, please

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.5</source>
                        <target>1.5</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

jboss repo

    <repositories>
        <repository>
            <id>central</id>
            <name>Maven Repository Switchboard</name>
            <layout>default</layout>
            <url>http://repo1.maven.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>jboss</id>
            <name>JBoss Maven Repository</name>
            <layout>default</layout>
            <url>http://repository.jboss.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

war: wtf is it good for?

So I pulled the goodies out of the war and put them in their maven-ish spots:

.
|-- pom.xml
`-- src
    `-- main
        |-- resources
        |   `-- messages.properties
        `-- webapp
            |-- WEB-INF
            |   |-- components.xml
            |   |-- pages.xml
            |   `-- web.xml
            |-- cheat.jspx
            |-- confirm.jspx
            |-- giveup.jspx
            |-- index.html
            |-- index.jsp
            |-- jboss-seam-numberguess.war
            |-- lose.jspx
            |-- niceforms.css
            |-- niceforms.js
            |-- numberGuess.jspx
            `-- win.jspx

there is a also a “images” directory under webapp I left out, cuz it’s kinda boring.

This structures is a little lame, but I don’t wanna change too much right now…

war deps

There are a two deps that I resolved to something like this:

  <dependency>
      <groupId>commons-beanutils</groupId>
      <artifactId>commons-beanutils</artifactId>
      <version>1.7.0</version>
  </dependency>
  <dependency>
      <groupId>jboss</groupId>
      <artifactId>jboss-seam-ui</artifactId>
      <version>2.0.0.BETA1</version>
  </dependency>

jar it

mkdir -p src/main/resources
touch src/main/resources/seam.properties

seam.properties has to end up in the root of the jar or seam will not work!!!! it will be broken!!! even though it is just a dumb empty properties file!!!! don’t forget it!!!!

You will end up with a nasty bit like:

javax.servlet.ServletException: Expected a child component type of UISelectItem/UISelectItems for component type javax.faces.SelectOne(selectGuessRadio).  Found null.

and even if you hack the jspx you will end up with something like:

javax.servlet.ServletException: /numberGuess.jspx(42,82) '#{numberGuess.currentGuess}' Target Unreachable, identifier 'numberGuess' resolved to null

And you may tear your hair out! And you may gnash your teeth! And when you find out the problem you may want to post it on your blog so noone else will have to suffer the same fate! I would imagine… 😉

jar it up some more

mkdir -p src/main/java/org/jboss/seam/example/numberguess/
cp NumberGuess.java ${_}

I snagged mese’f a copy of NumberGuess.java

The biggest thing the tutorial left to the imagination was the imports:

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

Presumably in the interests of brevity…

jar deps

  <dependency>
      <groupId>jboss</groupId>
      <artifactId>jboss-seam</artifactId>
      <version>2.0.0.BETA1</version>
  </dependency>

ear is totally wrong

I dunno what else to say about it… Ended up redoing the whole pom and even then it wasn’t right. The jboss-app.xml was always empty, I couldn’t get it to quit being dumb about being smart about ejbModules…

In the end, I clobbered the generated application.xml and jboss-app.xml with the ones from the seam-numberguess-2.1.0.CR1.ear

cp pageflow.jpdl.xml cheat.jpdl.xml target/in3 
cp jboss-app.xml application.xml target/in3/META-INF 
jar cf in3.ear -C target/in3 . 
mv in3.ear ${JBOSS_HOME}/server/default/deploy/

final product

As I said in the beginning this was not a 100% success, but it was a lot closer than when I started:

% wget http://brianin3d.googlepages.com/in3-project.tgz
% tar xfz in3-project.tgz
% cd in3-project
# this assumes you have JBOSS_HOME defined...
% mvn package &&  ( cd in3-ear/ ;  ./bother.sh )

Hit http://localhost:8080/seam-ng-mvn to see it in action.

A rough start, but at least it’s a start… 😀

Leave a Comment