betweenGo

Tag: JSTL

Tweets for 2010-01 and 2010-02

by on Feb.28, 2010, under Miscellaneous

Ruby on Rails

  • Numeric data types and zerofill. Explains what all those int(11) columns are in your Ruby on Rails tables. http://bit.ly/9Tcf7q #
  • undefined local variable or method "acts_as_list"? – Ruby Forum. Do ruby script/plugin install acts_as_list http://bit.ly/9kFWbG #
  • ruby on rails : adding child records to an existing parent without visiting the parent – Stack Overflow http://bit.ly/cQiGSP #
  • Multi-Table Inheritance in Rails – When two tables are one… This is not easy and I wish it was. http://bit.ly/9fbzgk #
  • has_many :through – count vs length vs size. Use count if u don’t want to load the contents of association into memory. http://bit.ly/dtqXe1 #
  • A gentle reminder about pluralizations. config/initializers/inflections.rb to customize pluralizations in Ruby on Rails http://bit.ly/bN9GO5 #
  • Ruby on Rails – Rails Migrations Cheatsheet – Dizzy. Pretty helpful. http://bit.ly/9wNvRx #
  • RailsGuides Migrations. Nice guide, especially about explaining the naming convention which I don’t like. http://bit.ly/cjZ7aB #

ATG

  • Configuring ATG to Send Email via Comcast SMTP – betweenGo. Configuring your ATG app to use your ISP’s SMTP server. http://bit.ly/7M5bhx #
  • Enabling non-XA Resources in JBoss 4.2 with ATG – betweenGo. http://bit.ly/aDN3Po #
  • Combining XML in ATG – betweenGo. Combining XML files not as straight-forward as w/ properties files but more flexible. http://bit.ly/8kVwvA Jan 12 12:00 PM

Eclipse

  • Debugging Applications in IBM Rational Application Developer. Page 12 for how to set up server for debugging. http://bit.ly/aaYUHb #

JavaScript

  • How can I submit a form along with some parameters using JavaScript? (JSF forum at JavaRanch). Answer #3 was helpful. http://bit.ly/b17ymm #

JSP

  • Testing Which Page Loaded your JSP Page Fragment – betweenGo. Simple enough to do w/ JSTL but I always forget how. :-) http://bit.ly/cEh7IZ #

Miscellaneous

  • Cygwin 1.7.x, mounts and /etc/fstab – betweenGo. Mounts are no longer saved from session to session in Cygwin 1.7. http://bit.ly/bmaYEu #
  • Git in 5 Minutes http://bit.ly/bSt3dd and Git for the lazy – Spheriki http://bit.ly/aefD17 #
  • The Thing About Git. Nice article describing how flexible Git is, especially compared to SVN. I may never use SVN again http://bit.ly/bD0tuS #
  • I use DreamHost and am shamelessly plugging them both for a referral and to try to win an iPad. Honestly they’re great. http://bit.ly/ctYv3Z #
Share
Leave a Comment :, , , , , , , , , , , , more...

ATG Currency Converter Not Working With JSTL c:set

by on Aug.12, 2009, under Page Development

Currency conversion confusion on Flickr!

This JSP code was not outputting the properly formatted amount.

<dspel:valueof value="${dollars}" converter="currency" />

I tried forcing it by specifying the conversion parameters.

<dspel:valueof value="${dollars}" converter="currency" locale="en-CA" format="#.00" currency="$" />

I then debugged atg.droplet.CurrencyTagConverter using Eclipse and found this code being executed.

public String convertObjectToString(DynamoHttpServletRequest pRequest,
                                 Object pValue, Properties pAttributes)
  throws TagConversionException
{
  if ((pValue == null) || (pValue instanceof String))
    return (String)pValue;

It turns out pValue was a String which is why it was never being formatted.  But why is it a String?

Well the code that sets dollars looks like this.

<dspel:tomap var="paymentGroup" param="commerceItem.paymentGroups[1]" />
<c:set var="dollars" value="0" />
<c:if test="${not empty paymentGroup}">
  <c:set var="dollars" value="${paymentGroup.amount}" />
</c:if>

Apparently c:set converts the Double to a String.

To work around this problem I did this.

$<dspel:valueof number="0.00" value="${dollars}" />

For further reading please see Tag Converters in the ATG Page Developer’s Guide.

Share
Leave a Comment :, , more...

ATG ForEach Output with Separators Between Items

by on Jul.24, 2009, under Page Development

Pez Collection

Sometimes you want to list each item in the collection with a separator in between like a comma or slash.  However the trick is to have the separator only in between items.

In ATG DSP you can use the ForEach droplet to iterate through each item in a collection.  However to put a separator between each item is not straight-forward with this droplet.  To do this I used JSTL to test if we are at the end of the collection.  If we are then I don’t add the separator, otherwise I do.

Here is an example.

<dspel:droplet name="/atg/dynamo/droplet/ForEach">
 <dspel:param name="array" param="dvds"/>
 <dspel:setvalue param="dvd" paramvalue="element" />
 <dspel:oparam name="outputStart">
  <dspel:getvalueof var="size" param="size" />
 </dspel:oparam>
 <dspel:oparam name="output">
  <dspel:valueof param="dvd.title" valueishtml="true"/>
  <dspel:getvalueof var="count" param="count" />
  <c:if test="${size != count}"> , </c:if>
 </dspel:oparam>
</dspel:droplet>

And here is the output for this example.

The Incredibles, Ratatouille, Cars

Do you have a better or more elegant solution?  Please feel free to let me know in the comments?

Share
2 Comments :, , more...

Get JSTL Vars from PageContext

by on May.04, 2009, under JSTL

JSTL sets its vars in the pageContext.  For example:

pageContext.setAttribute("foo", bar);


Therefore to get a JSTL variable use the pageContext within a tag or a JSP page.  For example:

// get item from pageContext and put in request
atg.servlet.DynamoHttpServletRequest drequest = atg.servlet.ServletUtil.getDynamoRequest(request);
drequest.setParameter("foo", pageContext.getAttribute("foo"));


Note that getAttribute assumes the variable is in the page scope.  If you want to get a variable from for example the request scope you would do this.

pageContext.getAttribute("foo", javax.servlet.PageContext.REQUEST_SCOPE);


For further reading please see PageContext.

Share
Leave a Comment :, , more...

Getting the request parameter

by on Apr.10, 2009, under JSTL, Page Development

I always forget how to do this so I thought I should write it down.

In JSP:

<%=request.getParameter("foo")%>
<img src="<%=request.getParameter("foo")%>">

In JSTL:

<c:out value="${param.foo}"/>

In DSP:

<dspel:valueof param="foo"/>
Share
Leave a Comment :, , more...

Unexplainable JSP Compilation Problem

by on Feb.04, 2009, under JSTL

I was getting a JSP compilation problem that I could not solve.

org.apache.jasper.JasperException: Unable to compile class for JSP
        at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

org.apache.jasper.JasperException: Unable to compile class for JSP
        at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:572)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)

java.lang.NumberFormatException: For input string: "${status.index}"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
        at java.lang.Integer.parseInt(Integer.java:447)
        at java.lang.Integer.valueOf(Integer.java:553)
        at org.apache.jasper.compiler.JspUtil.coerceToInt(JspUtil.java:752)
        at org.apache.jasper.compiler.Generator$GenerateVisitor.convertString(Generator.java:2949)

The major problem was this was happening on the server but not locally.  The compilation problem was occurring for this line.

<uportal:module definition="${module}" moduleIndex="${status.index}"/>

The moduleIndex value is “${status.index}”. Locally when the JSP compiler encounters this it knows to call my setter for moduleIndex that takes a String parameter. But on the server the JSP compiler seemed to insist on using the setter for moduleIndex that takes an integer parameter, hence the compilation problem.

I finally posted on the Sun Forums and with the help of evnafets I came up with two solutions.

  1. The correct solution is to upgrade my application to use JSTL 1.1.  Then the JSTL expressions such as “${status.index}” will be evaluated by the container.  Then I don’t have to have a setter that takes a String parameter, the JSTL expression, and evaluate it myself.  I can just use a setter that takes an integer parameter.
  2. The quick, hack solution which is to get rid of the setter that takes an integer parameter.  Wherever the application passes in an integer parameter, I change it to pass in a String representation of that integer.
Share
Leave a Comment :, , more...

Upgrading to JSTL 1.1

by on Feb.03, 2009, under JSTL

Based on this excellent post I came up with the following instructions for upgrading from JSTL 1.1.

  1. Update URI in JSP pages to use JSTL 1.1.
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  2. Install in WEB-INF/lib the two JSTL 1.1 jars, standard.jar and jstl.jar.  You can get these from The Jakarta Site – Standard 1.1 Taglib Downloads.
  3. Update the start of web.xml to look like this.
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
        version="2.4">
Share
Leave a Comment :, , more...

Display formatted HTML text

by on Aug.12, 2008, under JSTL, Page Development

In DSP to display formatted HTML text you use the valueishtml converter attribute.  For example:

<dspel:valueof param="displayName" valueishtml="true"/>

For example “foo &amp; bar” becomes “foo & bar”.

In JSTL to do this you tell JSTL not to escape the XML.  For example:

<c:out value="${displayName}" escapeXml="false" />
Share
Leave a Comment :, , , more...

Test if empty in JSTL

by on Jun.26, 2008, under JSTL

Singur suflet pustiu on Flickr

(Photo: Singur suflet pustiu by dani81_const)

This article, Expression Language Overview” href=”http://www.informit.com/articles/article.aspx?p=30946″>InformIT: The JSTL Expression Language > Expression Language Overview, informed me on how to test if something is empty or not.

Empty?

<c:if test="${empty foo}">...</c:if>

Not empty?

<c:if test="${not empty foo}">...</c:if>
Share
Leave a Comment :, , more...

JSTL for current URI

by on May.27, 2008, under JSTL

I was wondering how do get the current URI using JSTL and found this forum thread, JSTL EL for current page URL?.

If you want the actual URI of the JSP that is being rendered:

<c:out value="${pageContext.request.requestURI}"/>

If you want the original URI, which is probably the case, then:

<c:out value="${requestScope['javax.servlet.forward.request_uri']}"/>

In DSP if you want the original URI you can use the OriginatingRequest bean which implements the HttpServletRequest.

<dsp:valueof bean="/OriginatingRequest.requestURI" />
Share
Leave a Comment :, , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!