Forum OpenACS Q&A: ad_return_complaint and templating

Collapse
Posted by Hamilton Chua on
Hi ,

I used templating extensively on an application I am developing using
OpenACS4.2 and on occasion I use ad_return_complaint to return a
custom error message.

My problem is that the ad_return_complain uses old fashion ad_header
and ad_footer for formatting. I would like the error page to conform
to the master template that I have created for the site.

Any Ideas ....

Many Thanks

Collapse
Posted by Carl Coryell-Martin on
At civilution.com, we hacked ad_header and footer to each
source master.tcl and parse the upper and lower half of
master.adp respectively.  I am out  of the office until tues, if you
email me then, I'll post the code/mail it to you.

Cheers,

Collapse
Posted by Hamilton Chua on
Wow, that would be super - Yes please. Meanwhile I will think about
your suggestion and see if I can get it on my own..

Many Thanks.....

Collapse
Posted by Andrew Piskorski on
Hamilton, you'll want to look at the "returning pages in chunks" thread. Scroll down to my Aug. 28 post, and you'll see an example of doing exactly what Carl is talking about, above. That example is doing it on a Tcl page, but the only difference for putting it into an ad_header like proc might be how you decide which master template(s) to use.
Collapse
Posted by Hamilton Chua on
Thanks Andrew,

now I know where I was wrong. I was trying to use ns_adp parse when
there is a templating version of the adp parse.

Thanks again....

Collapse
Posted by Stephen . on
I think you are making it more complicated than it needs to be.

All the ad_return_whatever procs should ditch ad_header and ad_footer and call instead ad_return_template /path/to/global/notices/whatever-notice and templates etc. will be cake. (the path you'll have to work out yourself, because I'm lazy)

Notices should probably live under acs-subsite/global.

Collapse
Posted by Hamilton Chua on
I've thought of that so forgive my ignorance but is there a way to
pass the error message from ad_return_complaint vi
ad_return_template to my error template ?

Thanks for being industrious enough to post a response.

Regards ....

Collapse
Posted by Stephen . on
Yeah, just set a variable $the_error and use it in the template as @the_error@
Collapse
Posted by Andrew Piskorski on
Good point Stephen, that's definitely the right way to do it. Explicitly calling template::ad_parse should always be avoided whenever ad_return_template can do the job.
Collapse
Posted by Hamilton Chua on

I finally got it. Actually my colleague helped me with it. But for some time I found that validations in the ad_page_contract kept on reurning "Zero sized Reply".

This is how my friend Mello programmed it.

set error_message " "
proc_doc ad_return_complaint {exception_count exception_text} "Return a page complaining about the user's input (as opposed to an error in our software, for which ad_return_error is more appropriate)" {
    global error_message
    if { $exception_count == 1 } {
	set problem_string "a problem"
	set please_correct "it"
    } else {
	set problem_string "some problems"
	set please_correct "them"
    }
    set error_message $exception_text
    ad_return_template /www/templates/error 
}

...where /www/templates/error is a template which displays error_message in a manner which conforms to our site's designs (in other words it uses the master template).

However, I found that ad-page contract validations like notnull on variables returns a zero sized reply when calling ad_page contract programmed as above.

I made a little modification

proc_doc ad_return_complaint {exception_count exception_text} "Return a page complaining about the user's input (as opposed to an error in our software, for which ad_return_error is more appropriate)" {
    global error_message
    if { $exception_count == 1 } {
	set problem_string "a problem"
	set please_correct "it"
    } else {
	set problem_string "some problems"
	set please_correct "them"
    }
    set error_message $exception_text
    doc_return 200 text/html [template::adp_parse  [template::util::url_to_file "/www/templates/error" [ad_conn file]] {}] 
}

The later seems to have corrected the error I was experiencing.

Thanks to everyone for responding .....

Collapse
Posted by Denis Barut on
Hello,

Thanks for all your advices but nothing was working for me, and here how i resolve it :

ad_return_complaint
	if { $exception_count == 1 } {
	set problem_string "a problem"
	set please_correct "it"
    } else {
	set problem_string "some problems"
	set please_correct "them"
    }
	  
	global error_message
	
	set error_message "
to [ad_system_name]

We had $problem_string processing your entry:
	
    $exception_text
Please back up using your browser, correct $please_correct, and resubmit your entry.

Thank you. " rp_serve_abstract_file [acs_root_dir]/www/global/error
=========================================================


and the tcl/adp files :

error.tcl


global error_message
ad_return_template

error.adp


Problem with Your Input
@error_message@

Hope this could help.
Collapse
Posted by Don Baccus on
I recently snuck in a new template routine called "ad_return_exception_template" which allows for templated error messages and terminates processing to boot.

At the moment the only error template in acs-subsite/www/shared is "db-error.adp", designed to return a templated version of the "we had a database error" style error message.

Janine Sisk has written a couple of other simple templates for returning the "complaint" style errors.  She'll get this in the development branch soon.

I was going to wait until she was finished and committed the work before telling folks about this.

Collapse
Posted by Roberto Mello on
Don, this is great. Thanks a bunch.