Zope
  Home arrow Zope arrow Page 5 - ZPT Basics (part 3)
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ZOPE

ZPT Basics (part 3)
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2002-10-09

    Table of Contents:
  • ZPT Basics (part 3)
  • When In Rome...
  • Members Only
  • Sticks And Stones
  • Handling Errors
  • Endgame

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Ziff Davis Enterprise Virtual Tradeshows: Hot Topics, Cutting Edge Technology, Real-time Networking among IT Professionals. Learn more

    ZPT Basics (part 3) - Handling Errors
    (Page 5 of 6 )

    You can add primitive error-handling to your templates via the special "on-error" attribute, which allows you to specify a simple error message that is displayed when TAL encounters an error. Consider the following example:

    <font color="red" size="2" face="verdana" tal:on-error="string:Form input error" tal:attributes="color request/color; size request/size; face request/face"> Sticks and stones will break my bones </font>
    In this case, since my code requires the "size", "face" and "color" input variables to be specified as input parameters via the URL (notice that I have not used the "default" condition here, as I did in the previous example), an error will be generated if these variables are not present. However, rather than displaying the standard Zope error message,



    I can intercept the error with TAL's "on-error" attribute, and replace it with my own, simpler error message.



    "on-error" attributes are processed in a hierarchical manner, with TAL recursing upwards from the source of the error until it finds an "on-error" error handler. In the following example, even though the error is generated by the innermost <font> element, the error message generated comes from the outermost <div> element.

    <div tal:on-error="string:Form input error"> <b><font color="red" size="2" face="verdana" tal:attributes="color request/color; size request/size; face request/face"> Sticks and stones will break my bones </font> </b> </div>
    This is obviously a primitive example - you can do some pretty complex things with the "on-error" attribute. Take a look at http://www.zope.org/Wikis/DevSite/Projects/ZPT/RenderErrorHandlingStrategies for more information.

    More Zope Articles
    More By Harish Kamath, (c) Melonfire


     

       

    ZOPE ARTICLES

    - Creating Zope Products
    - Plone Content Types With Archetypes
    - Flat User Management in Zope
    - Creating Basic Zope Applications
    - Getting started with Zope for Linux and Sola...
    - ZPT Basics (part 4)
    - ZPT Basics (part 3)
    - ZPT Basics (part 2)
    - ZPT Basics (part 1)
    - Exception Handling In DTML
    - DTML Basics (part 4)
    - DTML Basics (part 3)
    - DTML Basics (part 2)
    - DTML Basics (part 1)
    - Using Zope With Apache




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway