Domanda

I have some jxpaths I want to put them in an enumeration I will be sharing with a JSF page using a map that will make them available to EL as the keys for jxpath to do a createPathAndSetValue on.

Then I can easily fill out a model without creating tons of getters and setters. like this:

<h:inputText value="#{backingBeanMap[backingBeanMap.billingAddress_postalCode]}" />

I have something like this

public enum MWField {
    isGiftJoin,
    billingAddress_postalCode,
    ...
    associates$3_memberInfo_membershipType_type;

    public final String xpath;

    MWField(){
        this.xpath = name().replace('_', '/').replace("$0", "[0]")
        .replace("$1", "[1]").replace("$2", "[2]")
        .replace("$3", "[3]").replace("$4", "[4]")
        .replace("$5", "[5]").replace("$6", "[6]")
        .replace("$7", "[7]").replace("$6", "[6]")
        .replace("$9", "[9]").replace("$10", "[10]");
    }
}

I use the name isGiftJoin or billingAddress_postalCode instead of uppercase names and do substitution of the _ with / in the constructor (so the xpath attribute is the actual xpath). So long as none of the properties have _ in the name (they don't), I am done. The enumerations won't be "UPPERCASE", but enumerations aren't really CONSTANTS in the sense that RED is a constant. Here they are instances of a class that point at data, and aren't intended to be "constant" in that way.

Are these names too wierd and non-standard? Is it silly to be chained to the C style constant UPPERCASE standard?

È stato utile?

Soluzione

Are you asking if you may name an enum whatever you want?

Of course; why not? Use a standard that works for you. Personally, I reserve all caps only for static finals, and tends towards class naming conventions for enum values.

I'm not a huge fan of underscores in names, but in your case, since you're deliberately creating a hierarchical structure, I have less of an issue with it.

I would wonder if an enum is really necessary for naming paths: do you need to use them in switch statements (in JDK 6 or less)? Is there a reason to represent them as anything other than strings? Are the names without the paths valuable?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top