Sorting Nested Properties

ATG’s looping droplet have the nice ability of sorting nested properties. For example say you have a repository item Person and it has a property address which is a repository item Address and you want to sort on the address’s street. Then you can do something like this.

<dspel :param name="sortProperties" value="+address.street"/>

ATG does this through the magic of DynamicBeans.

Share

Static Import

I never liked seeing people put constants in an interface and then implementing that interface in a class so that they can have direct access to those constants. That always seemed wrong to me and now this Sun article, Static Import, verifies my intuition.

In order to get around this, people sometimes put static members into an interface and inherit from that interface. This is a bad idea. In fact, it’s such a bad idea that there’s a name for it: the Constant Interface Antipattern (see Effective Java Item 17). The problem is that a class’s use of the static members of another class is a mere implementation detail. When a class implements an interface, it becomes part of the class’s public API. Implementation details should not leak into public APIs.

The suggested method is to use a static import.

import static java.lang.Math.PI;

However the article suggests using this sparingly.

Only use it when you’d otherwise be tempted to declare local copies of constants, or to abuse inheritance (the Constant Interface Antipattern). In other words, use it when you require frequent access to static members from one or two classes. If you overuse the static import feature, it can make your program unreadable and unmaintainable, polluting its namespace with all the static members you import. Readers of your code (including you, a few months after you wrote it) will not know which class a static member comes from. Importing all of the static members from a class can be particularly harmful to readability; if you need only one or two members, import them individually. Used appropriately, static import can make your program more readable, by removing the boilerplate of repetition of class names.

You can also do static import of methods.

import static com.betweengo.util.CollectionUtils.isEmpty;

However I would never do this, I like knowing where my static methods come from.

Share

JSP redirect to another page

I found on this forum how to redirect to another page in JSP. One of the respondents explained it perfectly.

Well you have two options. Either you’ll do a server side forward or a client side redirect.
Server side forward has no interaction with the browser and therefore the URL on the location bar won’t change.
But if you do the HTTP redirect, the browser is instructed to load the other page and the contents of the location will change.
It’s your call which one to choose.

forward:

<% if (s1.equals(s2) ) { %>

     <jsp:forward page="s2.jsp"/>

<% } %>

redirect:

<% if (s1.equals(s2) ) {

    response.sendRedirect("s2.jsp");

} %>
Share

ATG Parameter Names

Often in ATG form handler or droplet code one finds code like this:

public static final String OUTPUT = "output";

You can take advantage of ATG’s ParameterName class to represent any parameter name. From the ATG 2006.3 API Reference:

A ParameterName object can represent any parameter name used in Dynamo. Use this class when building your own droplets to create unique parameter names. The parameter names will then be stored in a global hashtable keyed by strings. Using this class allows the parameters of a droplet to be publicly available as well as enforcing good coding standards whereby the parameter name string only appears once in the java code.

Throughout ATG’s public source you can see that many parameter names have already been defined. For brevity sake I have omitted the “public final static” prefix.

ParameterName ARRAY = ParameterName.getParameterName("array");
ParameterName DEBUG = ParameterName.getParameterName("debug");
ParameterName DEFAULT = ParameterName.getParameterName("default");
ParameterName ELEMENT_NAME = ParameterName.getParameterName("elementName");
ParameterName EMPTY = ParameterName.getParameterName("empty");
ParameterName EQUAL = ParameterName.getParameterName("equal");
ParameterName GREATERTHAN = ParameterName.getParameterName("greaterthan");
ParameterName INDEX_NAME = ParameterName.getParameterName("indexName");
ParameterName IN_URL = ParameterName.getParameterName("inUrl");
ParameterName LESSTHAN = ParameterName.getParameterName("lessthan");
ParameterName NONCOMPARABLE = ParameterName.getParameterName("noncomparable");
ParameterName NON_SECURE_URL = ParameterName.getParameterName("nonSecureUrl");
ParameterName OBJ1 = ParameterName.getParameterName("obj1");
ParameterName OBJ2 = ParameterName.getParameterName("obj2");
ParameterName OUTPUT = ParameterName.getParameterName("output");
ParameterName OUTPUT_END = ParameterName.getParameterName("outputEnd");
ParameterName OUTPUT_START = ParameterName.getParameterName("outputStart");
ParameterName PATH = ParameterName.getParameterName("path");
ParameterName REVERSE_ORDER = ParameterName.getParameterName("reverseOrder");
ParameterName SECURE_URL = ParameterName.getParameterName("secureUrl");
ParameterName SORT_PROPERTIES = ParameterName.getParameterName("sortProperties");
ParameterName TRUE  = ParameterName.getParameterName("true");
ParameterName UNSET = ParameterName.getParameterName("unset");
ParameterName VALUE = ParameterName.getParameterName("value");
ParameterName CURRENCY_PARAM = ParameterName.getParameterName("currency");
ParameterName EURO_SYMBOL_PARAM = ParameterName.getParameterName("euroSymbol");
ParameterName LOCALE_PARAM = ParameterName.getParameterName("locale");
ParameterName TARGET_LOCALE_PARAM = ParameterName.getParameterName("targetLocale");
ParameterName YEN_SYMBOL_PARAM = ParameterName.getParameterName("yenSymbol");
Share

Stats on Dreamhost with WordPress

Analog: WWW logfile analysisOn my WordPress blogs hosted by Dreamhost to get stats I needed to add this to the .htaccess file.

# BEGIN Stats
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/(stats|failed_auth\.html).*$ [NC]
RewriteRule . - [L]
</IfModule>
# END Stats

This is further explained in the Dreamhost Wiki page Making stats accessible with htaccess.

Dreamhost uses Analog to generate web statistics. Other recommended AWStats which seems more powerful. Maybe I’ll switch if I feel the need.

Share