Controlling Jetty port in Maven 2

Overriding the jetty port used on mvn jetty:run was always something that annoyed me…
and that was due to my solution which had been to alter the project’s pom adding:

 	<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
 		<port>9090</port>
 		<maxIdleTime>60000</maxIdleTime>
 	</connector>

One problem with this is that i only need this on one of my dev machines (where the default 8080 port is
already occupied) and additionally this is not something that one would commit and enforce it to others.
It’s just plain wrong.

Maven Profiles

So, one might think, let’s use maven’s profiles for this. In the ~/.m2/settings.xml of the machine
in question, we can add

 <profile>
      <id>override-jetty-port</id>

       <activation>
         <activeByDefault>true</activeByDefault>
        </activation>

 	<!-- something to change the port here -->

 </profile>

But the problem is that it’s not easy to figure out the ‘something to change the port here’ part.
Jetty’s docs talk about the jetty.port property but it must be a system property, i.e. adding

 	<properties>
 		<jetty.port>8084</jetty.port>
 	</properties>

doesn’t do the trick.

Custom Hack

So, i first thought, let’s modify our pom, making use of a custom {jetty.port} in the connector’s implementation,
that let’s define a default value of 8080 for it inside the pom, and then let’s override this in our settings.xml !

But of course, it doesn’t feel right + i’d have to modify too many poms to go unnoticed by others…

Enlightment

And then it hit me… Use the MAVEN_OPTS environment parameter
export MAVEN_OPTS="-Xmx768m -Xms64m -Djetty.port=9090"

is all that it takes… Aargggggg…

Sometimes, things are impossibly easy!

Interviewed for platform.netbeans.org + Greek JUG + Geertjan

Interview

I was recently interviewed by Geertjan – mostly relating to Netbeans5.5 and the Tapestry support module. It was an interesting talk, go ahead and read it.
BTW, here’s the latest screenshot of the module’s autocomplete capabilities:

Greek JUG

So, anyway, i then ( on Dec 02 ) attended our local JUG (its schedule in greek), where i finally met those 2 Netbeans guys: Roman Strobl and Geertjan Wielenga
Their presentations were excellent and it was clear that everyone in the audience enjoyed them! I can say the exact same thing for the other 2 presentations, from T.Varias and D.Andreadis.
All in all, the event was a success – here are the photos! So, I’m already looking forward for the next one.

Geertjan

Geertjan is a very interesting and pleasant guy. We arranged for some team coding in my house where we came up with the error-annotation support for the tapestry module. Here it is in action:

We had to call it a day quite early though, cause i was once more sleepless (+ a bit sick) ! I must have been coding with my eyes closed during the last half-hour : ) So, anyway, we’ll probably meet again next week, when i’ll be at Prague… should be fun!

Java Applets Coding Contest Archives – A tribute to CFXweb

Java Applets Coding Contest Archives – A tribute to CFXweb

A few years ago I used to hang out at cfxweb.net

CFXweb is closed now, but when it started (2002) it was quite a popular site among demo sceners and amateur game developers – counting thousands of members and hosting graphics, 3D and AI related news and technical articles.

I still remembet when its creator, Civax, announced the 1st Java Applets Coding Contest… its theme was Image Distortion and more than 20 participants had sent their entries… I placed 10th with this bizzare entry … (don’t know what i was thinking of!) You can check out the rest of the entries here – many of which are still awesome.

I did better at the 7th contest, themed Particles. My entry “Gimme Pop” placed 2nd, but make sure you also check out the rest of them.

Anyway, I always get a smile on my face when i think back about that period (2000-2003) of my internet life. The previous one was a lot more darker… perhaps i’ll explain more in next posts!

Tacos 4.0.1 and Tapestry Support for Netbeans 5.5

We had two tapestry-related releases today:

Tacos 4.0.1

Tacos 4.0.1 was released a few hours ago.  
 
It’s mainly a stability release fixing 2 subtle bugs and  
enhancing the ajax encoder (for very pretty and short ajax urls). 
 
Make sure to also check out the previously undocumented but powerful 
ajax-enabled Table component. 
 
Thanks to all that contributed… 
 
Changes: 

* Docs for tacos:Table component. 
* Load external js synchronously. Fixes Bug127. 
* AjaxSubmit posts all the AjaxLinkSubmits before it. Fixes Bug130. 
* Do not clear current document after error (a failed ajax-post). 
* Jdk1.4 compatible class format for maven generated artifacts. 
* Add StringToListConverter. Allows updateComponents parameter to be specified as a comma-delimited String. 

* Add uniqueNames parameter in AjaxForm – forces the html name of each input control to stem from the component’s idPath (instead of the component’s id). 
* Support validators and translator in HtmlArea. Fixes Bug128. 
* Make buttons in tacos:Palette work. Fixes Bug129. 
* Remove hardcoded class attribute from tacos:Table. 
* Easier way for defining ajax exception and stale-session pages. 
* Enhance AjaxDirectServiceEncoder for ever prettier ajax urls.  

* Corrected links to tapestry’s component docs. 

nbtapestrysupport

Just released the first version of nbtapestrysupport.

It provides:

  • Hyperlink support in Tapestry configuration files for class names, files and libraries… CTRL+click everywhere!!!
  • Autocomplete in Tapestry configuration files for class names, files and others
  • Templates for new Tapestry files

Download the 2 nbms, then install the generic module first and then the tapestry module.

Enjoy!

Implementing a Firefox Plugin for Tapestry’s Reset Service

Implementing a Firefox Plugin for Tapestry’s Reset Service
Actually, i decided to make this a greasemonkey script, instead of a full FF plugin…

So, here’s the process:

  • 12:25. Install greasemonkey. ( http://greasemonkey.mozdev.org/ )
  • 12:27 Restart Firefox
  • 12:28 Search for a good tutorial on writing greasemonkey scripts.
  • 12:32 Hmm, http://greasemonkey.mozdev.org/authoring.html is a starting point, as is the http://mozdev.elliptic.fr/greasemonkey/linkify.user.js example.
  • 12:33 Create a file named tapestry.user.js somewhere. Open it up in an editor and also in FF. Make your changes in the editor, refresh in FF and click on install to use it.
  • 12:37 After the first hello world examples, let’s create something that adds an absolute positioned div in the current page, containing a static link for the moment.
  • 12:41 I used document.createElement(‘div’) to create the div and document.getElementsByTagName(“body”)[0].appendChild(resetDiv) to add it in the dom.
  • 12:44 I can write links in the div… with the ugly way (hope Jesse isn’t reading this), i.e. resetDiv.innerHTML='<a href=”…”>Cool</a>’
  • 12:45 location.href gives us the current url. we’ll have to hack it a bit to contruct a valid Tapestry reset url. For now, we’ll keep the url from the beggining to the last occurance of slash ‘/’ and append app?service=reset&page=Home afterwards.
  • 12:50 Done! Here’s the result.

Remember to configure the script so that it’s active only on the pages you want. Further updates might:

  • Recognize Tapestry sites and auto-enable the plugin.
  • Recognize and use the current page so that you won’t get redirected to Home.
  • Use better styling for the added div… It should be on the top of the page, with absolute positioning and semi-transparent.
  • See if this also works in Tapestry 3.

So, watch out for an update on this!

P.S.1 You have to enable Tapestry’s reset service for this to work.
P.S.2 If you’re wondering why you need this, then read on : )

While editing Tapestry’s templates (*.html) or configuration files (*.page, *.jwc, *.application, *.library) you can get instant save-refresh functionality if you disable cache (that’s org.apache.tapestry.disable-caching ). This however slows down request handling by a noticable amount and results in memory leaks because classloaders are thrown away on each request. I generally wouldn’t mind about this since it’s only used on development and it takes a LOT of refreshes before one gets an OutOfMemoryException.

But if you’re on AJAX ( read tacos or tapestry 4.1 ) then you’ll get that exception a lot more faster. So, in the last few months I’ve got into the habit of enabling cache + enabling the reset service ( that’s org.apache.tapestry.enable-reset-service. I usually keep an extra tab open in Firefox (having the url of the reset service) and whenever I make changes I hit refresh on that tab (so that all templates and Tapestry configurations are reloaded) and then return to my normal tab.

P.S.3 This was initially written in my internal TiddlyWiki, an awesome javascript-only wiki. I was really surprised when Howard recently commited (!!!) this wiki in Tapestry 5 trunk. In fact, I never knew a wiki could get itself committed! Well done Jeremy.

Netbeans5.5Beta2 bundled with JBoss4.0.4 : No way to change server port

Netbeans5.5Beta2 bundled with JBoss4.0.4 : No way to change server port

I’ve been playing a bit with Netbeans5.5, mostly due to Geertjan’s posts (esp. those describing how to build plugins supporting web frameworks). I even started nbtapestrysupport.

So, i’m on a new machine today and having decided to take a look at NB’s plugin support, i head for www.netbeans.org to download the 5.5 version. I’m however sidetracked with the plethora of the available installers… without thinking a lot, i go for the “NetBeans IDE 5.5 Beta 2 + JBoss Application Server 4.0.4 Bundle Installer“.

Installation went smoothly. After updating NB to include the subversion support, I was able to checkout from https://nbtapestrysupport.dev.java.net/svn/nbtapestrysupport/trunk/TapestryPlugin and build & run the project.

My next thought is ‘let’s see how well JBoss integrates’…so, going to the Runtime tab, right-clicking on JBoss and selecting Start results in “port 8080 already in use”. Oh well, there’s a background tomcat instance running on this pc, it shouldn’t be difficult to make jboss use another port, i.e. 7070.

Googling easily produces “change the following file:
server/xxx/deploy/jbossweb-tomcat55.sar/server.xml” and indeed, if i then issue “jboss_dir/bin/run.sh” it picks up the change and it works.

BUT, from within NetBeans it doesn’t and there’s no way to make it work… googling doesn’t help either… it’s as if there’s a hardcoded configuration somewhere inside NB’s JBoss integration code… Let’s look for a workaround then. Right click to “Add Server” and then browse to the JBoss installation folder is quite interesting. NB informs us that the configured port is 7070 (cool!) but also that ‘The domain instance you want to add already exists’ (sad but correct).

My question of course is, since the instance already exists and since it can indeed read the 7070 value, why doesn’t it use it ???

Anyway, I ended up renaming the instance (just a folder rename) which allowed me to add the server in the previously described way. And this leaves us with:

Why, oh why, can’t I delete (or even rename) the original (and non-working) JBoss server registration ???

Tapestry in press – Beginning POJOs

Tapestry in press – Beginning POJOs

I recently came across
Beginning POJOs: Lightweight Java Web Development Using Plain Old Java Objects in Spring, Hibernate, and Tapestry. From the reviews i’ve found, it looked like a nice book and since it does contain a whole chapter on Tapestry, I thought it would be nice to add it in Tapestry‘s site.

So, in order to fill in some (Tapestry related) descriptions, I contacted the author, Brian Sam-Bodden, requesting a detailed table of contents for that chapter. I was pleasantly surprised with Brian’s reply: a 2MB email containing all 70 pages of that chapter – and all this so that I can write a few lines of description… Wow, thanks Brian!

Anyway, the Tapestry chapter is quite interesting, covering Tapestry 4.0.x versions. It starts by describing installation and configuration of the framework, then goes on to explain the concept of pages and components. Several form components are shown and then we learn how to configure and use Hivemind services, tie them to EJB3 services and make use of Application State Objects. Of course, Tapestry annotations are in the mix as well… The chapter ends with more than a dozen pages on AJAX and Tacos. Examples include dynamic user input validation and autocompleters.

Heck, had this book been written 2 months later, it would have also had my name in the tacos section : )

Tapestry: Building Trees with Tacos and Annotations

So, what’s it like using annotations in Tapestry along with complex, cool and ajaxified components?
Well, let’s find out!

Html Template

Assuming that we want our html template to be as clean as possible, our CategoryTree.html file will
look like this:

 <body jwcid="@Border" title="Tree Management">
   <div id="note" >
     <h2>Tree Management</h2>
     <p>
       <a jwcid="expandAllLink" href="#">Expand All</a> |
       <a jwcid="collapseAllLink" href="#">Collapse All</a>
     </p>
     <div id="treeArea">
 		<div jwcid="tree" id="tree" style="overflow: auto; width: auto; height: auto;">
 	        <a jwcid="nodeLink" href="folder.png">
 	            <img jwcid="icon" align="absbottom"/>
 	            <span jwcid="nodeLabel">Node 1</span>
 	        </a>
 		</div>
     </div>
   </div>
 </body>

This includes 2 links to expand and collapse all nodes and the tree component. Tacos tree component
can be thought of as a smart iteration component (think of For or ForeEach) but it also knows in which
order the (visible) nodes should be rendered and it knows the node depth of each one of them.

So, here’s how the template looks like if you directly preview it in a browser
,
and here how it looks when tapestry renders it
.

Page Class

Ok, now let’s move on to the only other file needed, the CategoryTree.java (we would need a
CategoryTree.jwc if we didn’t use annotations). Here it is:

 public abstract class CategoryTree extends BaseCmsPage
 {
 	@InjectObject("service:mobilecms.categoryService")
 	public abstract CategoryService getCategoryService();
 
 	@Bean
 	public abstract EvenOdd getEvenOdd(); 
 
 	@Persist
 	@InitialValue("new java.util.HashSet()")
 	public abstract Set getTreeState();
 
 	@Persist
 	public abstract Category getNodeToEdit();
 	public abstract void setNodeToEdit(Category node);
 
 	@Component(type="tacos:Tree", bindings={"contentProvider=contentProvider",
 			"keyProvider=keyProvider", "state=treeState", "value=current", "rowStyle=bean:evenOdd"} )
 	public abstract Tree getTree();
 
 	@Component(type="DirectLink", bindings={"listener=listener:editNode",
 			"parameters={current.id, current.name}"} )
 	public abstract DirectLink getNodeLink();
 
 	@Component(type="DirectLink", bindings={"listener=listener:collapseAll"} )
 	public abstract DirectLink getCollapseAllLink();	
 
 	@Component(type="DirectLink", bindings={"listener=listener:expandAll"} )
 	public abstract DirectLink getExpandAllLink();	
 
 	@Component(type="Insert", bindings={"value=current.langName",
 			"class=(nodeToEdit!=null and current.id == nodeToEdit.id) ? 'selected' : null"} )
 	public abstract Insert getNodeLabel();
 
 	public abstract Category getCurrent();
 
 	public IKeyProvider getKeyProvider() {
 		return new CategoryKeyProvider();
 	}
 
 	public ITreeContentProvider getContentProvider() {
 		return new CategoryTreeContentProvider(getCategoryService());
 	}	
 
 	public void editNode(String id, String name) {
 		setNodeToEdit(new Category(id, name, null, null));
 	}
 
 	public void collapseAll() {
 		getTreeManager().collapseAll();
 	}
 
 	public void expandAll() {
 		getTreeManager().expandAll();
 	}	
 
     public ITreeManager getTreeManager() {
         return new TreeManager(getTreeState(), getContentProvider(), getKeyProvider());
     }

Ok, so I lied (a bit). You still need a few extra classes to run this (i.e. your domain model)
but that’s obvious! Here, we make use of Category (our bean), CategoryService (our way of
finding Categories) and trivial implementations of IKeyProvider and ITreeContentProvider
(the tree’s way of accessing data).

Annotations Used

Now, from top to bottom, here are the annotations explained:

  1. @InjectObject: Inject the specified object-service in our class, simple and powerful. Services
    are defined using Hivemind or Spring -the one used here is a singleton.
  2. @Bean: Create (and inject) a simple javabean. The bean is constructed on each render. We use this
    to achieve alternate coloring of each tree’s node.
  3. @Persist: Store / remembers the value of the property across multiple renders. Uses session by default.
  4. @InitialValue: We don’t want that property to be null at the beggining, and we’re lazy to write java
    code to do this, so we simply add this annotation.
  5. @Component: This one defines the components that are used in this page. In 4.1.1+ versions of Tapestry
    the type attribute can be deduced by the framework if it matched the return type of the annotated method.
    The id of each component is not specified since the framework uses by default the related property name,
    i.e. getNodeLink() is for id nodeLink. This leaves us with the bindings attribute which i find quite
    easy to follow.

From then on, the code contains 6 more methods, all one-liners! Notice how easy it is to collapse or
expand all nodes, and how we add a specific style to the selected node (tip: see the bindings of
getNodeLabel() and the editNode() method).

Ajax Included???

Oh, and BTW, the tree you’ve just created is AJAX enabled! Clicking to expand or collapse a node will
result in only the tree refreshing. You’ll have to add a “nodeLinkAjax=false” to have normal, old-style
refreshes (http://tacos.sourceforge.net/components/Tree.html).

Hope you liked this annotations and tree tour! I’ll soon get back with some entries on Tapestry 4.1.1
new goodies. Always have fun!

Edit POJOs in Tapestry

Well, the idea is simple, use something like

<span jwcid="@edit:EditObject" object="ognl:pojo"/>

and instantly generate insert-delete-update pages of the given pojo.

I think there’s such a component over at Trails but i’ve yet to find time to check this out as much as i want to.

Recently, there was a post by Hugo Duncan describing a similar component with source code attached.

And now, we have BeanForms by Daniel Gredler, which is a detailed description of yet another solution.

Wow! That’s amazing! I’ll try to get some time this week to play with it + see how AJAX and TACOS can fit to it… What a great community Tapestry has!