I need a version of paramValue that does type checking, the following
example should explain why:
Form post field called “id”.
My event checks the Request Collection for the existence of the key
(“id”) and sets it to zero if it doesn’t exist.
event.paramValue(‘Id’,0);
The problem is that “id” has the potential to be a blank string rather
than a value that evaluates as a numeric.
I need id to be zero if it is not a numeric or does not exist.
Id is in actual fact a series of differently name primaryKey related
variable names: articleId, pageId, etc. depending on which event
handler is executing.
I'm currently performing a reassign of the value to itself using Val,
e.g.
rc = event.getCollection()
event.paramValue("id",0) // set to zero if var does not exist
rc.id = Val(rc.id) // set to zero if not numeric
I’ve decorated Event.paramValue() for application specific needs and believe that is the way to go. For example, the existing code will allow zero-length strings to be considered defined; however, in my application(s), I tend to desire the “default value” in that situation.
A few lines of code and you’ll have everything you need. One more reason ColdBox rocks.
I wasn't aware of the paramValue() in the event, and after thinking about it
for a while I can see why it exists, but also why I didn't go looking for
it.
I am going to assume that your event, has more than one or 2 of these
things, which is what I began to find and ended up just doing something like
this rather than the way you are doing it.
Var rc = event.getCollection();
Var rcData = {temp1="String", temp2=100};
structCopy(rc, rcData);
But I see what you mean about being core. But what would also be good is a
paramValues() which allows the collection to be passed, and is basically a
wrapper for something like the above, that would be nice too, in reality
would it be any quicker in ColdBox in terms of writing less code than this
way
From: Andrew Scott [mailto:andrews@andyscott.id.au]
Sent: Tuesday, 22 February 2011 11:08 AM
To: 'coldbox@googlegroups.com'
Subject: RE: [coldbox:8212] Re: Enhancement to paramValue
I wasn't aware of the paramValue() in the event, and after thinking about
it
for a while I can see why it exists, but also why I didn't go looking for
it.
I am going to assume that your event, has more than one or 2 of these
things, which is what I began to find and ended up just doing something
like
this rather than the way you are doing it.
Var rc = event.getCollection();
Var rcData = {temp1="String", temp2=100}; structCopy(rc, rcData);
But I see what you mean about being core. But what would also be good is a
paramValues() which allows the collection to be passed, and is basically a
wrapper for something like the above, that would be nice too, in reality
would it be any quicker in ColdBox in terms of writing less code than this