views:

34

answers:

2

We use Jakarta Taglibs to ouput some basic HTML form elements like selects. It appears this library has been retired.. are there any good alternates? Looking for something simple that will take a Java Map and output it to HTML.

+2  A: 

You can use JSTL <c:forEach> for this. Each iteration gives a Map.Entry back which in turn has getKey() and getValue() methods. Assuming that you've a Map<String, String> with option values as map keys and option labels as map values, here's an example:

<select name="foo">
    <c:forEach items="${bean.map}" var="entry">
        <option value="${entry.key}" ${entry.key == param.foo ? 'selected' : ''}>${entry.value}</option>
    </c:forEach>
</select>

As to the replacement of the legacy Jakarta taglib, have a look at MVC frameworks which offers taglibs to bind the model with the view. For example Struts 1.x (in essence a slight evolution of the legacy Jakarta taglib), Struts 2.x (a further evolution) and JSF (another evolution in the same direction as Struts 2.x).

Here's an example of how to render a HTML <select> in JSF.

<h:selectOneMenu id="foo" value="#{bean.selectedItem}">
    <f:selectItems value="#{bean.selectItems}" />
</h:selectOneMenu>

JSF binds it transparently with the model without the need to write your own controller (servlet).

BalusC
Standard JSTL is the way to go if you use JSPs. I'm starting to prefer Velocity for the same use cases.
duffymo
And I myself prefer Facelets. But that's another story :)
BalusC
+1  A: 

This project has been retired to attic because almost features are avaibles using standard implementation enmbebed in applicaton servers.

http://attic.apache.org/projects/jakarta-taglibs.html

This project is alive in http://tomcat.apache.org/taglibs/

angelcervera
JSTL was arised out of only a small part of the Jakarta taglib. The OP is in essence looking for a replacement of the [`<input:select>`](http://jakarta.apache.org/taglibs/doc/input-doc/usage.html#select) tag, which isn't available in JSTL.
BalusC