29 September 2009

Create Custom JSF Facelet Component

Because it took me a while to find the right steps I don't want to hold back my findings:

1. Create a facelet taglib:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE facelet-taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib>
    <namespace>http://unibe.ch/tags</namespace>
    <tag>
        <tag-name>publikation</tag-name>
        <component>
            <component-type>unibe.PublikationComponent</component-type>
        </component>
    </tag>
</facelet-taglib>


2. Add taglib to web.xml

<context-param>
  <param-name>facelets.LIBRARIES</param-name>
  <param-value>/WEB-INF/facelets/publikation.taglib.xml</param-value>

</context-param>

3. Add component to faces-config.xml

<component>
  <component-type>unibe.PublikationComponent</component-type>
  <component-class>ch.unibe.search.ui.PublikationComponent</component-class>
</component>


4. Implement Component. (I just extended UIOutput for my purposes):

public class PublikationComponent extends UIOutput {

    private PublikationTO getPublikation() {
        ValueExpression ve = getValueExpression("item");
        if (ve != null) {
            return (PublikationTO) ve
                    .getValue(getFacesContext().getELContext());
        } else {
            return null;
        }
    }

    @Override
    public void encodeBegin(FacesContext context) throws IOException {
        final ResponseWriter writer = context.getResponseWriter();
        PublikationTO publikation = this.getPublikation();
        if (publikation != null) {
            writer.startElement("p", null);
            for (AutorTO autor : publikation.getAutoren()) {
                if (autor.getId() == null) {
                    writer.writeText(autor.getName() + ", "
                            + autor.getVorname(), null);
                    writer.writeText(" ", null);
                } else {
                    writer.startElement("a", null);
                    writer.writeAttribute("href", "result.jsf?autorId="
                            + autor.getId(), null);
                    writer.writeText(autor.getName() + ", "
                            + autor.getVorname(), null);
                    writer.endElement("a");
                    writer.writeText(" ", null);
                }
            }
            writer.writeText("(" + publikation.getJahr() + ") ", null);
            writer.writeText(publikation.getTitel(), null);
            writer.endElement("p");
        } else {
            writer.write("Fehler");
        }
    }
}


5. Use your component

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    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:unibe="http://unibe.ch/tags" template="/template.xhtml">
    <ui:define name="content">
        <h1>Resultate</h1>
        <h:dataTable id="items" value="#{search.results}" var="result">
            <h:column>
                <unibe:publikation item="#{result}" />   
            </h:column>
        </h:dataTable>
        <h:messages layout="table" style="font-size:12px;" />
    </ui:define>
</ui:composition>


That's it ;-)

11 September 2009

NetBeans toString() Generator Version 0.3.0

Thanks to Christians help we could release a new version of the toString() generator for NetBeans. You can download it here.

Please also find the release notes on the NetBeans plugin portal.

Currently we just have all features of Eclipse 3.5 toString() generator implemented.
You can find out what keeping us busy in JIRA.

Any feature requests are highly appreciated!

09 September 2009

Chrisitan Pervoelz joined NetBeans toString() Generator Project

Today Chrisitan Pervoelz from Berlin joined the Kenai project nbtostring
Welcome to the team!

With his help we will able to release faster new versions. Today we release 0.2.0. It contains two improvements: 1) existing toString() well be overwritten 2) you can choose how the toString() is generated (String concatenation or StringBuilder)
Download 0.2.0

07 September 2009

First very basic version of toString() Generator for NetBeans released

I was faster than expected and released a first version of the toString() generator. It is very basic in the moment but I'm working on it to add all features of Eclipse 3.5 toString() generator.

nbtostring in the News

Today my NetBeans toString() generator is mentioned in the German news of JAXenter.

I will try to hurry and release a first version next week.

03 September 2009

Open Source Discussion in Swiss Government

In the last few month there were several discussions about open source usage in government or educational sector in Switzerland. Even the parliament is discussion about that topic.
My question in this debate is if the parliamentarians now what open source really means?!

A lot of people think that first of all open source software is free respectively that closed source software isn't free of charge. But both expectations are wrong!

If we have a look at the Java EE application server market we see that some vendors like JBoss or Sun have open source licenses but if compare them the whole package with support, patches etc. with vendors with closed source licenses there is sometimes not a big difference between these two.
That's an important fact, because if you have problems with the product in production you are dependent on patches from the vendor. And you wont get these if you don't pay for it!

As a conclusion if you are just a user of the software and are not able to change or even read the code, there is no difference between open and closed software.

Don't get me wrong, because I'm a big fan of open source and collaborate in several open source projects but keep my argument in mind if you discuss with "non IT people".

Your opinion is highly appreciated.