开发者

What java view technology is this?

It seems velocity and freemarker look fairly similiar, at least for basic usage.

Anyhow, what is the "built in" or standard view framework called? It looks like:

<c:if test="${someobject.property != null}"&开发者_JAVA百科gt;


It's most likely Unified Expression Language (EL) which is used by JSTL.

I think it would look more like

<c:if test="${someobject.property != null}">


That's indeed JSTL. It's however not builtin, but all you need to do is to just drop jstl-1.2.jar in the /WEB-INF/lib and declare one of its taglibs in top of the JSP page as per the TLD documentation, e.g. JSTL core:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

This way you can use the in the link listed tags. Most of the core tags are just flow control tags. JSTL also has XML and SQL taglibs, but they are intented for quick prototyping only and shouldn't be used in real production. Then there is the Format (fmt) taglib which is great for internationalization and localization (i18n and l10n). Finally there is the useful functions (fn) taglib which provides simple EL functions.

Then there are the ${} things. This is called expression language. It just accesses "backend data" (the attributes) in any of the page, request, session and application scopes in a Javabean like way with help of PageContext#findAttribute() and calling the Javabean getters. If you understand scriptlets, then you'll understand the following example:

${user.address.street}

which roughly resolves to

<%= pageContext.findAttrubute("user").getAddress().getStreet() %>

EL is nullsafe. When ${user} or ${user.address} resolves to null, then it will just skip it all and display nothing. In scriptlets you would have gotten a NPE on the nested calls or just plain null on the last call.

Then there is the unified EL, denoted by the #{} syntax. It's (as far) only used in combination with JavaServer Faces (JSF). It is able do to a call a Javabean setter on the last property. E.g.

<h:inputText name="foo" value="#{bean.foo}">

will behind the scenes roughly do like follows

pageContext.findAttribute("bean").setFoo(request.getParameter("foo"));

It's by the way not a view technology. JSP itself is already the view technology at its own. JSTL is just a taglib. EL is just part of the JSP spec. The other view technology provided by Java EE is Facelets which is XHTML based and provides much more seamless integration for JSF than JSP does.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜