Pages

2008-11-18

Making a "selectable" list component using facelets

Disclaimer: This is not a defense of jsf. If markup were an animal specie, then using jsf would get you arrested for mistreatment. I'm hoping that JavaFX wil give us a better way to make RIAs.

in web.xml

<context-param>
    <param-name>facelets.LIBRARIES</param-name>
    <param-value>/WEB-INF/somewhere/you/decide/whatever.tablib.xml</param-value>
</context-param>

in whatever.taglib.xml

<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC
  "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
  "facelet-taglib_1_0.dtd">

<facelet-taglib>
  <namespace>http://www.yourdomain.com/anothernameyoudecide</namespace>
  <tag>
    <tag-name>li</tag-name>
    <source>li.xhtml</source>
  </tag>
</facelet-taglib>

in li.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:c="http://java.sun.com/jstl/core">
    <c:choose>
        <c:when test="#{selectedPageName == pageName}">
            <li class="#{class} menuItemSelected"><ui:insert /></li>
        </c:when>
        <c:otherwise>
            <li class="#{class} menuItemNotSelected"><ui:insert /></li>
        </c:otherwise>
    </c:choose>
</ui:composition>

(I was particularily impressed to see that I could just add the existing classes as easy as it is done above. It's one of those rare moments when I think that it would be wonderful if it was this simple, -just to find out that it actually is!)

making the menu

<ui:component xmlns:jsp="http://java.sun.com/JSP/Page"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:y="http://www.yourdomain.com/anothernameyoudecide"
    xmlns:c="http://java.sun.com/jstl/core">
<ul class="horisontalMenu" id="topMenu">
        <li jsfc="y:li" pageName="home"><a href="Home.faces">#{bundle['topmenu.home']}</a></li>
        <li jsfc="y:li" pageName="search"><a href="Search.faces">#{bundle['topmenu.search']}</a></li>
        <li jsfc="y:li" pageName="reports"><a href="Reports.faces">#{bundle['topmenu.reports']}</a></li>
    </ul>
</ui:component>

setting the selected top menu

easy as just dropping this into the ui:composition of the facelet your displaying:
<ui:param name="selectedPageName" value="home"/>

2008-11-17

Quick wins with Java 6 update 10

So, the other day I needed a count down timer. For the pomodoro technique. A quick search on the net: java timer applet gives this http://javaboutique.internet.com/JavaTimer/ Seems like it was uploaded 2000-12-11. (Nice thing about Java. Just works, also with old stuff.)

Problem solved. But, it would be funny to see if I could use any of the new features of Java 6 update 10, so I downloaded the source code, updated the html-file to include <PARAM name="draggable" value="true"/> in the applet tag.

Open from the downloaded folder, alt-drag, WOW, it works! Cool!!!

2008-11-08

Using git locally, perforce centrally.

Work In Progress...

It probably comes as no surprise for people who know me that I find Perforce a bit awkward. I have suggested in an earlier post that the only reason anyone would go for Perforce is because they already have a big Perforce repository from before.

That is not to say I'm against version control. I use version control for every project that lasts for more than a few hours, for both strategical and tactical purposes I believe that it makes me about 10% more effective, mostly because it works as a project wide undo, removing the fear of making mistakes. This is, to me, the tactical purpose of version control(*). To have that benefit however, you have to commit your work frequently. If commiting you work is hard, or can have unpleasant side effects (think breaking the build on the ci server), then you'd probably just commit every time you've finished a piece of work.

By using git at your local computer, you can have almost(**) all the benefits of having a modern version control system, without having to move the entire company to another vcs. Just do "git init", "git add ." and "git commit" in your workspace and you have a local repository.

You can now commit your work as often as you like, branch out crazy ideas, and, when you've finished a piece of work, you just commit it to the central repository using standard perforce tools.

Hint: You might find it useful to let the master branch follow perforce exactly, and do your work inside a "local" branch. That way you can even use git tools for resolving conflicts before each commit.

So, what do you loose? Nothing. You still commit to the perforce repository every time you've finished a piece of work, so no significant revision histrory is going to be lost.

Disclaimer: I work at a smart, nice company, where nobody cares if you install cygwin, git or whatever, as long as it is safe, legal and doesn't hamper productivity. Installing git may not be a smart idea at every other company :)

* One of the strategic benefits is of course that you have the revision history when you wonder what went into a specific release.
**You still have to "open files for edit". :/