Forum OpenACS Q&A: setting default values in ad_page_contract

I am working through the examples at:
https://openacs.org/doc/acs-templating/demo/

on the second example, using bind variables in your query, I am trying to specify a default value of "1" for user_id.

The documentation at:
https://openacs.org/api-doc/proc-view?proc=ad_page_contract&source_p=1&version_id=

shows that the way to specify default values is this format:
{name[:flag,flag,flag] default}

I have tried like so:
user_id:integer "1"
and also like so:
user_id:integer 1

But the page outputs:
We had some problems with your input:

* You must supply a value for user_id
* You must supply a value for 1
Instead of using the default value.

What am I doing wrong?

Thank you.

Collapse
Posted by Dave Bauer on
elements with a default value need to be surrounded by

{ }

as in the example

{ name[:flag,flag,flag] default }

That is, it is formatted as a two element tcl list where the first element is name:flag and the second element is default.

Collapse
Posted by Matthew Smith on
Here's what I have, I beleive I am already doing as you suggested:

ad_page_contract {
uses bind variables in a query
@author Matthew Smith
} {
user_id:integer "1"
} -properties {
users:onerow
}

set query " select
first_name, last_name
from
ad_template_sample_users
where user_id = :user_id"

db_1row users_query $query -column_array users

Collapse
Posted by Dave Bauer on
Almost!

ad_page_contract {
uses bind variables in a query
@author Matthew Smith
} {
{user_id:integer "1"}
} -properties {
users:onerow
}

The list of ad_page_contract variables is one list. Each element is also a list. If its just the name:flag you can omit the { } around it but if it has a default they are required.

Collapse
Posted by Matthew Smith on
I've got it now. Thank you, Dave.