Sunday November 30, 2003
JSTL Tips o' the Day Here's a couple of tips to help you in your JSP development with JSTL:
- The <c:out> tag has a default attribute you can use to provide a default value when the value in your the variable you're trying to write is null. This is much easier than using if statements. Example: <c:out value="${user.firstName}" default="None Given" />.
- You can populate dynamic values in a key from your ResourceBundle using the <fmt:param> tag. For instance, if you have a message with a link in ApplicationResources.properties - and you want to populate it with a struts-forward, it's easy with JSTL:
ApplicationResources.properties:
mainMenu.link=Click <a href="{0}">here</a> to return to the Main Menu.In your JSP:
<fmt:message key="mainMenu.link"> <fmt:param><html:rewrite forward="mainMenu"/></fmt:param> </fmt:message>
Usually I try not to put any HTML in ApplicationResources.properties, but I don't think a minimal amount hurts anything. Of course, you could put all the HTML in your JSP, so mainMenu.link changes to "Click {0} to return to the Main Menu." and your JSP changes to:
<fmt:message key="mainMenu.link">
<fmt:param>
<html:link forward="mainMenu">here</html:link>
</fmt:param>
</fmt:message>
Enjoy! Posted in Java at Nov 30 2003, 06:14:20 PM MST 1 Comment
Matt Raible is a Web Architect who enjoys developing applications with open source technologies. Contact me for rates.
Search This Site
Recent Entries
- What's Next
- Jack's Mohawk
- LinkedIn Cuts 10% (a.k.a. The Journey is Over)
- Happy Birthday Abbie!
- Moving from Spring's XML to Annotations in AppFuse
- Free Maven Training in New Orleans on Election Day
- AppFuse Light ยป AppFuse, Maven Archetypes and Shared Web Assets
- Great Weekend in Montana
- Colorado Software Summit 2008 Wrapup
- RESTful Web Applications with Subbu Allamaraju
<c:if test="${0 == (myval >> 3) }" >Basically shifting myval 3 to the right and testing for 0. How do I do it? I have tried all sorts of things with no support using EL syntax.Posted by dsuspense on December 01, 2003 at 11:41 AM MST #