20031130 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

Comments:

Here's a JSLT question I have not been able to answer or figure out. If I want to do a bitwise shift of an in within an test expression, how do I do it? Suppose I want to write:
<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 #

Post a Comment:
  • HTML Syntax: Allowed
Click me to subscribe
Matt Raible is a Web Architect who enjoys developing applications with open source technologies. Contact me for rates.
« December 2008
SunMonTueWedThuFriSat
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
   
       
Today

Recent Entries

Tag Cloud