Wednesday, January 31, 2007

Loop over a list of model elements with an iterator faclet tag in JSF

What about and ? Why do one need another loop tag?

  1. If your container component has specific requirements on the type of its child component you can't go with the known tags because they put there own components as child-components on the container.

  2. Both of them cannot be used if you need a dynamic evaluation of model elements

You can use the tag as follows to iterator over a list of employees to print out there names:

<my:iterator value="#{bean.employees}" var="employee" > <<tr:outputText value="#{employee.name}" /> </my:iterator>

The Tag assumes a value of type List.

The Java Code of the Facelets Tag Handler:

public class IteratorTag extends TagHandler

{

private final TagAttribute _value;

private final TagAttribute _var;

public IteratorTag(TagConfig p_arg0)

{

super(p_arg0);

_value = getRequiredAttribute("value");

_var = getRequiredAttribute("var");

}

public void apply(FaceletContext p_facelets,

UIComponent p_parentComponent) throws IOException, FacesException, FaceletException, ELException

{

// get the value binding behind attr "value"

List list = (List) _value.getObject(p_facelets, List.class);

int idIndex = 0;

for (Object object : list)

{

// get the name of the variable

String varName = _var.getValue(p_facelets);

// set new variable into faclets attribute map

p_facelets.setAttribute(varName, object);

nextHandler.apply(p_facelets, p_parentComponent);

// update ID of last created component from nextHandler

String clientId = p_parentComponent.getClientId(p_facelets.getFacesContext()) + "_dynamicChild"+idIndex;

List children = p_parentComponent.getChildren();

children.get(children.size()-1).setId(clientId);

idIndex++;

}

}

}

Friday, January 26, 2007

Good Agile Karma

Leif hat mir folgenden, Artikel über Aigle Software Entwicklung zukommen lassen:

Abstract:

This article will focus on behavior patterns that enable teams to realize the most benefits of Agile rollout and sustain the experience. This article assumes that you have already implemented Agile process in your organization.

URL:

http://www.infoq.com/articles/agile-karma