Enhancement to paramValue

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

Isn't event.getValue('Id',0); what you need?

Regards,
Andrew Scott
http://www.andyscott.id.au/

From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of Martin
Sent: Monday, 21 February 2011 10:00 AM
To: ColdBox Platform
Subject: [coldbox:8195] Enhancement to paramValue

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)

Request Context Decorator should allow you to change the behavior as you see fit.
http://wiki.coldbox.org/wiki/Recipes:My_First_Request_Context_Decorator.cfm

Hi, Martin:

Why not...

Variable = val(event.paramValue("id",0))

Kevin

Hi Kevin

I broke out the val and paramValue lines in my example for clarity, it
of course makes it neater if you do both inline as per your example.

Hi Andrew

It looks like the decorator might be the solution but it would be nice
if the enhancement went into the core rather than my own library.

Thanks

Martin

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.

-A

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 :slight_smile:

Regards,
Andrew Scott
http://www.andyscott.id.au/

From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of Martin
Sent: Tuesday, 22 February 2011 10:11 AM
To: ColdBox Platform
Subject: [coldbox:8212] Re: Enhancement to paramValue

Hi Kevin

I broke out the val and paramValue lines in my example for clarity, it of
course makes it neater if you do both inline as per your example.

Hi Andrew

It looks like the decorator might be the solution but it would be nice if

the

And after having said that, I just realised that there is a way in ColdBox
to append to the Collection.

Regards,
Andrew Scott
http://www.andyscott.id.au/

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

way