开发者

Good alternate for Jakarta Taglibs?

开发者 https://www.devze.com 2023-01-22 04:03 出处:网络
We use Jakarta Taglibs to ouput some basic HTML form elements like selects.It appears this library has been retired..are the开发者_JAVA技巧re any good alternates?Looking for something simple that will

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


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).


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消