I can’t remember what it is called, but I need to do a sort of conditional statement inside of a CFSet statement. What I mean is something like the following
siteSettings = {
mailserversmtpport = resourceBean.getValue('mailsmtp'), // SMTP Port (If the method returns no len() then default to 25)
mailserverpopport = resourceBean.getValue('mailpop'), // POP port (If the method returns no len() then default to 110)
};
So I am building a structure with the smtp and pop port for a mail server. I have a method call that gets a value from a bean. If that value doesn’t exist then it is just going to return a 0 length string. Is it possible (in ColdFusion 8) to have the value be 25 and 110 if returned values have no length without do cfif statements?
The neatest, and in my opinion best, way to do this would be to add two methods to your bean: getMailSmtp() and getMailPop().
Put the conditional logic in there – so the method returns your default value if it’s not specified.
Something like this:
Alternatively, you could alter your getValue() method to accept a second argument – a default value. Then, if the value doesn’t exist, it would return the default:
I’d personally go for the first method, as this means that any time you call getMailSmtp() in your application, the logic is applied.
You could even combine the methods, so your getMailSmtp() method returns
getValue("mailsmtp", 25).