Java, ATG Dynamo
There are all sorts of things you can do with JSTL. Beyond the immediate c:if and c:choose stuff, there's a good deal of power built into EL itself.
Tertiary operator, for example. It helps to be concise. (Of course, it helps if I would have tested this myself -- tertiary operators are JSTL 1.1 and ATG is JSTL 1.0. Oh well, there's always scriptlets.)
<span class="<c:out value='${test ? "even" : "odd"}'/>">some text</span>Basic arithmetic. You may not think that this is so impressive, but it helps. Before, it was test if instanceof Number and then cast down to a primitive, and all kinds of ugliness.
<dsp:tomap id="pi" param="shippingGroup.priceInfo"/>
<dsp:getvalueof id="subtotal" param="subtotal">
<c:set var="total" value="${subtotal + pi.rawShipping + pi.additionalShippingAmount + pi.giftWrapAmount + taxAmount}"/>
<dsp:valueof value='<%= pageContext.getAttribute("total") %>' converter="currency"/>
</dsp:getvalueof>And then of course there's the dynamic map attributes. You really don't want to look at the before version.
<dsp:getvalueof id="taxPriceInfoMap" bean="ShoppingCart.current.taxPriceInfo.shippingItemsTaxPriceInfos"
idtype="java.util.Map">
<dsp:getvalueof id="shippingGroupId" param="shippingGroup.id" idtype="java.lang.String">
<c:set var="taxAmount" value="${taxPriceInfoMap[shippingGroupId].amount}"/>
<dsp:valueof value='<%= pageContext.getAttribute("taxAmount") %>' converter="currency"/>
</dsp:getvalueof>
</dsp:getvalueof>Still wish there was some kind of DynamicBeans included, but I suppose I can't ask for too much at once.
http://www.ognl.org/2.6.7/Documentation/html/LanguageGuide/index.html
httlp://www.ognl.org/2.6.7/Documentation/html/LanguageGuide/apa.html
http://www.ognl.org/2.6.7/Documentation/html/LanguageGuide/selection.html
If you're using the EL's conditional operator, then you're using JSP 2.0. So, you can just do:
<span class="${test ? "even" : "odd"}">some text</span>In other words, no JSTL involved. In addition, JSP 2.0 makes the EL "natively" available for request-time tag attribute values. That means you can use the EL instead of scripting expressions (
<%= %>) . So, your<dsp:valueOf>tag would look like:<dsp:valueof value="${taxAmount}" converter="currency"/>or:
<dsp:valueof value="${pageScope.taxAmount}" converter="currency"/>Not sure about the diverse objects blowup, but as for getting the size of a list, JSTL 1.1 provides a length function:
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
${fn:length(theList)}
The next question is why would you be accessing pageContext in a JSP Expression when you could just access it in an EL Expression....
Oh....I get it, ATG Dynamo isn't JSP 2.0 yet?
Ugh. Glad I'm no longer struggling with that heavy beast of an app server.
The customer in this case wanted a rough custom calculation on one page that didn't include the true cost of shipping. The order runs through all the payment processors as usual at checkout.