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
Search This Site
Recent Entries
- Wine Tasting in Napa Valley
- How to build a Shot-Ski
- Bus Project Update
- Farewell to the 2011-2012 Ski Season
- Cruising around the Western Caribbean
- Spring Break!
- A Spectacular Trip to Stockholm and Madrid
- Comparing Web Frameworks and HTML5 with Play Scala at Jfokus 2012
- Play Framework 2.0 with Peter Hilton at Jfokus
- Secure JSON Services with Play Scala and SecureSocial
<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 12:41 PM MST #